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