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