comparison Framework/StoneException.h @ 1062:2d6237221ff1

Merge
author Benjamin Golinvaux <bgo@osimis.io>
date Tue, 15 Oct 2019 10:54:53 +0200
parents 5df50e0f0390
children 6dd90b8d1589
comparison
equal deleted inserted replaced
1061:eb28dfe432f7 1062:2d6237221ff1
34 ErrorCode_Success, 34 ErrorCode_Success,
35 ErrorCode_OrthancError, // this StoneException is actually an OrthancException with an Orthanc error code 35 ErrorCode_OrthancError, // this StoneException is actually an OrthancException with an Orthanc error code
36 ErrorCode_ApplicationException, // this StoneException is specific to an application (and should have its own internal error code) 36 ErrorCode_ApplicationException, // this StoneException is specific to an application (and should have its own internal error code)
37 ErrorCode_NotImplemented, // case not implemented 37 ErrorCode_NotImplemented, // case not implemented
38 38
39 ErrorCode_PromiseSingleSuccessHandler, // a Promise can only have a single success handler
40 ErrorCode_PromiseSingleFailureHandler, // a Promise can only have a single failure handler
41
42 ErrorCode_CanOnlyAddOneLayerAtATime, 39 ErrorCode_CanOnlyAddOneLayerAtATime,
43 ErrorCode_CommandJsonInvalidFormat, 40 ErrorCode_CommandJsonInvalidFormat,
44 ErrorCode_WebGLContextLost, 41 ErrorCode_WebGLContextLost,
45 ErrorCode_Last 42 ErrorCode_Last
46 }; 43 };
47
48 44
49 45
50 class StoneException 46 class StoneException
51 { 47 {
52 protected: 48 protected:
66 } 62 }
67 63
68 virtual const char* What() const 64 virtual const char* What() const
69 { 65 {
70 return "TODO: EnumerationToString for StoneException"; 66 return "TODO: EnumerationToString for StoneException";
71 }
72 };
73
74 class OpenGLContextLostException : public StoneException
75 {
76 public:
77 explicit OpenGLContextLostException(void* context)
78 : StoneException(ErrorCode_WebGLContextLost)
79 , context_(context)
80 {
81 }
82 virtual const char* What() const
83 {
84 return "The OpenGL/WebGL context has been lost!";
85 }
86 void* context_;
87 };
88
89 class StoneOrthancException : public StoneException
90 {
91 protected:
92 Orthanc::OrthancException& orthancException_;
93
94 public:
95 explicit StoneOrthancException(Orthanc::OrthancException& orthancException) :
96 StoneException(ErrorCode_OrthancError),
97 orthancException_(orthancException)
98 {
99 }
100
101 Orthanc::ErrorCode GetOrthancErrorCode() const
102 {
103 return orthancException_.GetErrorCode();
104 }
105
106 virtual const char* What() const
107 {
108 return orthancException_.What();
109 }
110 };
111
112 class StoneApplicationException : public StoneException
113 {
114 protected:
115 int applicationErrorCode_;
116 mutable std::string errorMessage_;
117
118 public:
119 explicit StoneApplicationException(int applicationErrorCode) :
120 StoneException(ErrorCode_ApplicationException),
121 applicationErrorCode_(applicationErrorCode)
122 {
123 }
124
125 int GetApplicationErrorCode() const
126 {
127 return applicationErrorCode_;
128 }
129
130 virtual const char* What() const
131 {
132 if (errorMessage_.size() == 0)
133 errorMessage_ = boost::lexical_cast<std::string>(applicationErrorCode_);
134
135 return errorMessage_.c_str();
136 } 67 }
137 }; 68 };
138 } 69 }
139 70
140 // See https://isocpp.org/wiki/faq/misc-technical-issues#macros-with-multi-stmts 71 // See https://isocpp.org/wiki/faq/misc-technical-issues#macros-with-multi-stmts
161 92
162 93
163 94
164 95
165 96
166
167
168
169
170
171
172
173
174 /* 97 /*
175 Explanation: 98 Explanation:
176 99
177 ORTHANC_ASSERT(a) 100 ORTHANC_ASSERT(a)
178 ORTHANC_EXPAND(GET_ORTHANC_ASSERT(a, ORTHANC_ASSERT2, ORTHANC_ASSERT1, UNUSED)(a)) 101 ORTHANC_EXPAND(GET_ORTHANC_ASSERT(a, ORTHANC_ASSERT2, ORTHANC_ASSERT1, UNUSED)(a))