comparison Applications/StoneWebViewer/Resources/Orthanc/Plugins/OrthancPluginException.h @ 1538:d1806b4e4839

moving OrthancStone/Samples/ as Applications/Samples/
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 11 Aug 2020 13:24:38 +0200
parents StoneWebViewer/Resources/Orthanc/Plugins/OrthancPluginException.h@b750b6eab453
children
comparison
equal deleted inserted replaced
1537:de8cf5859e84 1538:d1806b4e4839
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-2020 Osimis S.A., Belgium
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 }