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