Mercurial > hg > orthanc-stl
comparison Resources/Orthanc/Plugins/OrthancPluginException.h @ 0:4e889a8e8be2
initial commit of the viewer plugin
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 04 Jul 2023 19:15:27 +0200 |
parents | |
children | dd0cd39e6259 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4e889a8e8be2 |
---|---|
1 /** | |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium | |
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium | |
7 * | |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU General Public License as | |
10 * published by the Free Software Foundation, either version 3 of the | |
11 * License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 **/ | |
21 | |
22 | |
23 #pragma once | |
24 | |
25 #if !defined(HAS_ORTHANC_EXCEPTION) | |
26 # error The macro HAS_ORTHANC_EXCEPTION must be defined | |
27 #endif | |
28 | |
29 | |
30 #if HAS_ORTHANC_EXCEPTION == 1 | |
31 # include <OrthancException.h> | |
32 # define ORTHANC_PLUGINS_ERROR_ENUMERATION ::Orthanc::ErrorCode | |
33 # define ORTHANC_PLUGINS_EXCEPTION_CLASS ::Orthanc::OrthancException | |
34 # define ORTHANC_PLUGINS_GET_ERROR_CODE(code) ::Orthanc::ErrorCode_ ## code | |
35 #else | |
36 # include <orthanc/OrthancCPlugin.h> | |
37 # define ORTHANC_PLUGINS_ERROR_ENUMERATION ::OrthancPluginErrorCode | |
38 # define ORTHANC_PLUGINS_EXCEPTION_CLASS ::OrthancPlugins::PluginException | |
39 # define ORTHANC_PLUGINS_GET_ERROR_CODE(code) ::OrthancPluginErrorCode_ ## code | |
40 #endif | |
41 | |
42 | |
43 #define ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code) \ | |
44 throw ORTHANC_PLUGINS_EXCEPTION_CLASS(static_cast<ORTHANC_PLUGINS_ERROR_ENUMERATION>(code)); | |
45 | |
46 | |
47 #define ORTHANC_PLUGINS_THROW_EXCEPTION(code) \ | |
48 throw ORTHANC_PLUGINS_EXCEPTION_CLASS(ORTHANC_PLUGINS_GET_ERROR_CODE(code)); | |
49 | |
50 | |
51 #define ORTHANC_PLUGINS_CHECK_ERROR(code) \ | |
52 if (code != ORTHANC_PLUGINS_GET_ERROR_CODE(Success)) \ | |
53 { \ | |
54 ORTHANC_PLUGINS_THROW_EXCEPTION(code); \ | |
55 } | |
56 | |
57 | |
58 namespace OrthancPlugins | |
59 { | |
60 #if HAS_ORTHANC_EXCEPTION == 0 | |
61 class PluginException | |
62 { | |
63 private: | |
64 OrthancPluginErrorCode code_; | |
65 | |
66 public: | |
67 explicit PluginException(OrthancPluginErrorCode code) : code_(code) | |
68 { | |
69 } | |
70 | |
71 OrthancPluginErrorCode GetErrorCode() const | |
72 { | |
73 return code_; | |
74 } | |
75 | |
76 const char* What(OrthancPluginContext* context) const | |
77 { | |
78 const char* description = OrthancPluginGetErrorDescription(context, code_); | |
79 if (description) | |
80 { | |
81 return description; | |
82 } | |
83 else | |
84 { | |
85 return "No description available"; | |
86 } | |
87 } | |
88 }; | |
89 #endif | |
90 } |