Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/StoneException.h @ 1512:244ad1e4e76a
reorganization of folders
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jul 2020 16:21:02 +0200 |
parents | Framework/StoneException.h@30deba7bc8e2 |
children | 4fb8fdf03314 |
comparison
equal
deleted
inserted
replaced
1511:9dfeee74c1e6 | 1512:244ad1e4e76a |
---|---|
1 /** | |
2 * Stone of Orthanc | |
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 Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the 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 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #pragma once | |
23 | |
24 #include "Toolbox/LinearAlgebra.h" | |
25 | |
26 #include <OrthancException.h> | |
27 | |
28 #include <boost/lexical_cast.hpp> | |
29 | |
30 #include <iostream> | |
31 | |
32 namespace OrthancStone | |
33 { | |
34 enum ErrorCode | |
35 { | |
36 ErrorCode_Success, | |
37 ErrorCode_OrthancError, // this StoneException is actually an OrthancException with an Orthanc error code | |
38 ErrorCode_ApplicationException, // this StoneException is specific to an application (and should have its own internal error code) | |
39 ErrorCode_NotImplemented, // case not implemented | |
40 | |
41 ErrorCode_CanOnlyAddOneLayerAtATime, | |
42 ErrorCode_CommandJsonInvalidFormat, | |
43 ErrorCode_WebGLContextLost, | |
44 ErrorCode_Last | |
45 }; | |
46 | |
47 | |
48 | |
49 class StoneException | |
50 { | |
51 protected: | |
52 OrthancStone::ErrorCode errorCode_; | |
53 | |
54 public: | |
55 explicit StoneException(ErrorCode errorCode) : | |
56 errorCode_(errorCode) | |
57 { | |
58 } | |
59 | |
60 virtual ~StoneException() {} | |
61 | |
62 ErrorCode GetErrorCode() const | |
63 { | |
64 return errorCode_; | |
65 } | |
66 | |
67 virtual const char* What() const | |
68 { | |
69 switch (errorCode_) | |
70 { | |
71 case ErrorCode_Success: | |
72 return "Success"; | |
73 break; | |
74 case ErrorCode_OrthancError: | |
75 return "OrthancError"; | |
76 break; | |
77 case ErrorCode_ApplicationException: | |
78 return "ApplicationException"; | |
79 break; | |
80 case ErrorCode_NotImplemented: | |
81 return "NotImplemented"; | |
82 break; | |
83 case ErrorCode_CanOnlyAddOneLayerAtATime: | |
84 return "CanOnlyAddOneLayerAtATime"; | |
85 break; | |
86 case ErrorCode_CommandJsonInvalidFormat: | |
87 return "CommandJsonInvalidFormat"; | |
88 break; | |
89 case ErrorCode_WebGLContextLost: | |
90 return "WebGLContextLost"; | |
91 break; | |
92 case ErrorCode_Last: | |
93 return "Last"; | |
94 break; | |
95 default: | |
96 return "Unknown exception code!"; | |
97 } | |
98 } | |
99 }; | |
100 } | |
101 | |
102 // See https://isocpp.org/wiki/faq/misc-technical-issues#macros-with-multi-stmts | |
103 // (or google "Multiple lines macro C++ faq lite" if link is dead) | |
104 #define ORTHANC_ASSERT2(cond,streamChainMessage) \ | |
105 if (!(cond)) { \ | |
106 std::stringstream sst; \ | |
107 sst << "Assertion failed. Condition = \"" #cond "\" Message = \"" << streamChainMessage << "\""; \ | |
108 std::string sstr = sst.str(); \ | |
109 throw ::Orthanc::OrthancException(::Orthanc::ErrorCode_InternalError,sstr.c_str()); \ | |
110 } else (void)0 | |
111 | |
112 #define ORTHANC_ASSERT1(cond) \ | |
113 if (!(cond)) { \ | |
114 std::stringstream sst; \ | |
115 sst << "Assertion failed. Condition = \"" #cond "\""; \ | |
116 std::string sstr = sst.str(); \ | |
117 throw ::Orthanc::OrthancException(::Orthanc::ErrorCode_InternalError,sstr.c_str()); \ | |
118 } else (void)0 | |
119 | |
120 # define ORTHANC_EXPAND( x ) x | |
121 # define GET_ORTHANC_ASSERT(_1,_2,NAME,...) NAME | |
122 # define ORTHANC_ASSERT(...) ORTHANC_EXPAND(GET_ORTHANC_ASSERT(__VA_ARGS__, ORTHANC_ASSERT2, ORTHANC_ASSERT1, UNUSED)(__VA_ARGS__)) | |
123 | |
124 | |
125 | |
126 | |
127 | |
128 /* | |
129 Explanation: | |
130 | |
131 ORTHANC_ASSERT(a) | |
132 ORTHANC_EXPAND(GET_ORTHANC_ASSERT(a, ORTHANC_ASSERT2, ORTHANC_ASSERT1, UNUSED)(a)) | |
133 ORTHANC_EXPAND(ORTHANC_ASSERT1(a)) | |
134 ORTHANC_ASSERT1(a) | |
135 | |
136 ORTHANC_ASSERT(a,b) | |
137 ORTHANC_EXPAND(GET_ORTHANC_ASSERT(a, b, ORTHANC_ASSERT2, ORTHANC_ASSERT1, UNUSED)(a,b)) | |
138 ORTHANC_EXPAND(ORTHANC_ASSERT2(a,b)) | |
139 ORTHANC_ASSERT2(a,b) | |
140 | |
141 Note: ORTHANC_EXPAND is required for some older compilers (MS v100 cl.exe ) | |
142 */ | |
143 | |
144 | |
145 | |
146 | |
147 | |
148 |