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