/src/graphicsmagick/Magick++/lib/Exception.cpp
Line | Count | Source |
1 | | // This may look like C code, but it is really -*- C++ -*- |
2 | | // |
3 | | // Copyright Bob Friesenhahn, 1999-2024 |
4 | | // |
5 | | // Implementation of Exception and derived classes |
6 | | // |
7 | | |
8 | | #define MAGICK_IMPLEMENTATION |
9 | | #define MAGICK_PLUSPLUS_IMPLEMENTATION |
10 | | |
11 | | #include "Magick++/Include.h" |
12 | | #include <string> |
13 | | #include <errno.h> |
14 | | #include <string.h> |
15 | | |
16 | | using namespace std; |
17 | | |
18 | | #include "Magick++/Exception.h" |
19 | | |
20 | | // Construct with message string |
21 | | Magick::Exception::Exception( const std::string& what_ ) |
22 | 491k | : std::exception(), |
23 | 491k | _what(what_) |
24 | 491k | { |
25 | 491k | } |
26 | | |
27 | | // Copy constructor |
28 | | Magick::Exception::Exception( const Magick::Exception& original_ ) |
29 | 0 | : exception(original_), |
30 | 0 | _what(original_._what) |
31 | 0 | { |
32 | 0 | } |
33 | | |
34 | | // Assignment operator |
35 | | Magick::Exception& Magick::Exception::operator= (const Magick::Exception& original_ ) |
36 | 0 | { |
37 | 0 | if(this != &original_) |
38 | 0 | { |
39 | 0 | this->_what = original_._what; |
40 | 0 | } |
41 | 0 | return *this; |
42 | 0 | } |
43 | | |
44 | | // Return message string |
45 | | /*virtual*/ const char* Magick::Exception::what( ) const throw() |
46 | 0 | { |
47 | 0 | return _what.c_str(); |
48 | 0 | } |
49 | | |
50 | | /* Destructor */ |
51 | | /*virtual*/ Magick::Exception::~Exception ( ) throw () |
52 | 491k | { |
53 | 491k | } |
54 | | |
55 | | // |
56 | | // Warnings |
57 | | // |
58 | | |
59 | | Magick::Warning::Warning ( const std::string& what_ ) |
60 | 18.2k | : Exception(what_) |
61 | 18.2k | { |
62 | 18.2k | } |
63 | | |
64 | | /*virtual*/ Magick::Warning::~Warning ( ) throw () |
65 | | { |
66 | | } |
67 | | |
68 | | Magick::WarningUndefined::WarningUndefined ( const std::string& what_ ) |
69 | 0 | : Warning(what_) |
70 | 0 | { |
71 | 0 | } |
72 | | |
73 | | /*virtual*/ Magick::WarningUndefined::~WarningUndefined ( ) throw () |
74 | | { |
75 | | } |
76 | | |
77 | | Magick::WarningBlob::WarningBlob ( const std::string& what_ ) |
78 | 0 | : Warning(what_) |
79 | 0 | { |
80 | 0 | } |
81 | | |
82 | | /*virtual*/ Magick::WarningBlob::~WarningBlob ( ) throw () |
83 | | { |
84 | | } |
85 | | |
86 | | Magick::WarningCache::WarningCache ( const std::string& what_ ) |
87 | 0 | : Warning(what_) |
88 | 0 | { |
89 | 0 | } |
90 | | |
91 | | /*virtual*/ Magick::WarningCache::~WarningCache ( ) throw () |
92 | | { |
93 | | } |
94 | | |
95 | | Magick::WarningCoder::WarningCoder ( const std::string& what_ ) |
96 | 11.5k | : Warning(what_) |
97 | 11.5k | { |
98 | 11.5k | } |
99 | | |
100 | | /*virtual*/ Magick::WarningCoder::~WarningCoder ( ) throw () |
101 | | { |
102 | | } |
103 | | |
104 | | Magick::WarningConfigure::WarningConfigure ( const std::string& what_ ) |
105 | 0 | : Warning(what_) |
106 | 0 | { |
107 | 0 | } |
108 | | |
109 | | /*virtual*/ Magick::WarningConfigure::~WarningConfigure ( ) throw () |
110 | | { |
111 | | } |
112 | | |
113 | | Magick::WarningCorruptImage::WarningCorruptImage ( const std::string& what_ ) |
114 | 6.64k | : Warning(what_) |
115 | 6.64k | { |
116 | 6.64k | } |
117 | | |
118 | | /*virtual*/ Magick::WarningCorruptImage::~WarningCorruptImage ( ) throw () |
119 | | { |
120 | | } |
121 | | |
122 | | Magick::WarningDelegate::WarningDelegate ( const std::string& what_ ) |
123 | 0 | : Warning(what_) |
124 | 0 | { |
125 | 0 | } |
126 | | |
127 | | /*virtual*/ Magick::WarningDelegate::~WarningDelegate ( ) throw () |
128 | | { |
129 | | } |
130 | | |
131 | | Magick::WarningDraw::WarningDraw ( const std::string& what_ ) |
132 | 0 | : Warning(what_) |
133 | 0 | { |
134 | 0 | } |
135 | | |
136 | | /*virtual*/ Magick::WarningDraw::~WarningDraw ( ) throw () |
137 | | { |
138 | | } |
139 | | |
140 | | Magick::WarningFileOpen::WarningFileOpen ( const std::string& what_ ) |
141 | 0 | : Warning(what_) |
142 | 0 | { |
143 | 0 | } |
144 | | |
145 | | /*virtual*/ Magick::WarningFileOpen::~WarningFileOpen ( ) throw () |
146 | | { |
147 | | } |
148 | | |
149 | | Magick::WarningImage::WarningImage ( const std::string& what_ ) |
150 | 0 | : Warning(what_) |
151 | 0 | { |
152 | 0 | } |
153 | | |
154 | | /*virtual*/ Magick::WarningImage::~WarningImage ( ) throw () |
155 | | { |
156 | | } |
157 | | |
158 | | Magick::WarningMissingDelegate::WarningMissingDelegate ( const std::string& what_ ) |
159 | 0 | : Warning(what_) |
160 | 0 | { |
161 | 0 | } |
162 | | |
163 | | /*virtual*/ Magick::WarningMissingDelegate::~WarningMissingDelegate ( ) throw () |
164 | | { |
165 | | } |
166 | | |
167 | | Magick::WarningModule::WarningModule ( const std::string& what_ ) |
168 | 0 | : Warning(what_) |
169 | 0 | { |
170 | 0 | } |
171 | | |
172 | | /*virtual*/ Magick::WarningModule::~WarningModule ( ) throw () |
173 | | { |
174 | | } |
175 | | |
176 | | Magick::WarningMonitor::WarningMonitor ( const std::string& what_ ) |
177 | 0 | : Warning(what_) |
178 | 0 | { |
179 | 0 | } |
180 | | |
181 | | /*virtual*/ Magick::WarningMonitor::~WarningMonitor ( ) throw () |
182 | | { |
183 | | } |
184 | | |
185 | | Magick::WarningOption::WarningOption ( const std::string& what_ ) |
186 | 61 | : Warning(what_) |
187 | 61 | { |
188 | 61 | } |
189 | | |
190 | | /*virtual*/ Magick::WarningOption::~WarningOption ( ) throw () |
191 | | { |
192 | | } |
193 | | |
194 | | Magick::WarningRegistry::WarningRegistry ( const std::string& what_ ) |
195 | 0 | : Warning(what_) |
196 | 0 | { |
197 | 0 | } |
198 | | |
199 | | /*virtual*/ Magick::WarningRegistry::~WarningRegistry ( ) throw () |
200 | | { |
201 | | } |
202 | | |
203 | | Magick::WarningResourceLimit::WarningResourceLimit ( const std::string& what_ ) |
204 | 0 | : Warning(what_) |
205 | 0 | { |
206 | 0 | } |
207 | | |
208 | | /*virtual*/ Magick::WarningResourceLimit::~WarningResourceLimit ( ) throw () |
209 | | { |
210 | | } |
211 | | |
212 | | Magick::WarningStream::WarningStream ( const std::string& what_ ) |
213 | 0 | : Warning(what_) |
214 | 0 | { |
215 | 0 | } |
216 | | |
217 | | /*virtual*/ Magick::WarningStream::~WarningStream ( ) throw () |
218 | | { |
219 | | } |
220 | | |
221 | | Magick::WarningType::WarningType ( const std::string& what_ ) |
222 | 0 | : Warning(what_) |
223 | 0 | { |
224 | 0 | } |
225 | | |
226 | | /*virtual*/ Magick::WarningType::~WarningType ( ) throw () |
227 | | { |
228 | | } |
229 | | |
230 | | Magick::WarningXServer::WarningXServer ( const std::string& what_ ) |
231 | 0 | : Warning(what_) |
232 | 0 | { |
233 | 0 | } |
234 | | |
235 | | /*virtual*/ Magick::WarningXServer::~WarningXServer ( ) throw () |
236 | | { |
237 | | } |
238 | | |
239 | | // |
240 | | // Errors |
241 | | // |
242 | | |
243 | | Magick::Error::Error ( const std::string& what_ ) |
244 | 473k | : Exception(what_) |
245 | 473k | { |
246 | 473k | } |
247 | | |
248 | | /*virtual*/ Magick::Error::~Error ( ) throw () |
249 | | { |
250 | | } |
251 | | |
252 | | Magick::ErrorUndefined::ErrorUndefined ( const std::string& what_ ) |
253 | 0 | : Error(what_) |
254 | 0 | { |
255 | 0 | } |
256 | | |
257 | | /*virtual*/ Magick::ErrorUndefined::~ErrorUndefined ( ) throw () |
258 | | { |
259 | | } |
260 | | |
261 | | Magick::ErrorBlob::ErrorBlob ( const std::string& what_ ) |
262 | 1.61k | : Error(what_) |
263 | 1.61k | { |
264 | 1.61k | } |
265 | | |
266 | | /*virtual*/ Magick::ErrorBlob::~ErrorBlob ( ) throw () |
267 | | { |
268 | | } |
269 | | |
270 | | Magick::ErrorCache::ErrorCache ( const std::string& what_ ) |
271 | 185 | : Error(what_) |
272 | 185 | { |
273 | 185 | } |
274 | | |
275 | | /*virtual*/ Magick::ErrorCache::~ErrorCache ( ) throw () |
276 | | { |
277 | | } |
278 | | |
279 | | Magick::ErrorCoder::ErrorCoder ( const std::string& what_ ) |
280 | 100k | : Error(what_) |
281 | 100k | { |
282 | 100k | } |
283 | | |
284 | | /*virtual*/ Magick::ErrorCoder::~ErrorCoder ( ) throw () |
285 | | { |
286 | | } |
287 | | |
288 | | Magick::ErrorConfigure::ErrorConfigure ( const std::string& what_ ) |
289 | 22 | : Error(what_) |
290 | 22 | { |
291 | 22 | } |
292 | | |
293 | | /*virtual*/ Magick::ErrorConfigure::~ErrorConfigure ( ) throw () |
294 | | { |
295 | | } |
296 | | |
297 | | Magick::ErrorCorruptImage::ErrorCorruptImage ( const std::string& what_ ) |
298 | 321k | : Error(what_) |
299 | 321k | { |
300 | 321k | } |
301 | | |
302 | | /*virtual*/ Magick::ErrorCorruptImage::~ErrorCorruptImage ( ) throw () |
303 | | { |
304 | | } |
305 | | |
306 | | Magick::ErrorDelegate::ErrorDelegate ( const std::string& what_ ) |
307 | 17.6k | : Error(what_) |
308 | 17.6k | { |
309 | 17.6k | } |
310 | | |
311 | | /*virtual*/ Magick::ErrorDelegate::~ErrorDelegate ( ) throw () |
312 | | { |
313 | | } |
314 | | |
315 | | Magick::ErrorDraw::ErrorDraw ( const std::string& what_ ) |
316 | 7.18k | : Error(what_) |
317 | 7.18k | { |
318 | 7.18k | } |
319 | | |
320 | | /*virtual*/ Magick::ErrorDraw::~ErrorDraw ( ) throw () |
321 | | { |
322 | | } |
323 | | |
324 | | Magick::ErrorFileOpen::ErrorFileOpen ( const std::string& what_ ) |
325 | 179 | : Error(what_) |
326 | 179 | { |
327 | 179 | } |
328 | | |
329 | | /*virtual*/ Magick::ErrorFileOpen::~ErrorFileOpen ( ) throw () |
330 | | { |
331 | | } |
332 | | |
333 | | Magick::ErrorImage::ErrorImage ( const std::string& what_ ) |
334 | 0 | : Error(what_) |
335 | 0 | { |
336 | 0 | } |
337 | | |
338 | | /*virtual*/ Magick::ErrorImage::~ErrorImage ( ) throw () |
339 | | { |
340 | | } |
341 | | |
342 | | Magick::ErrorMissingDelegate::ErrorMissingDelegate ( const std::string& what_ ) |
343 | 44 | : Error(what_) |
344 | 44 | { |
345 | 44 | } |
346 | | |
347 | | /*virtual*/ Magick::ErrorMissingDelegate::~ErrorMissingDelegate ( ) throw () |
348 | | { |
349 | | } |
350 | | |
351 | | Magick::ErrorModule::ErrorModule ( const std::string& what_ ) |
352 | 0 | : Error(what_) |
353 | 0 | { |
354 | 0 | } |
355 | | |
356 | | /*virtual*/ Magick::ErrorModule::~ErrorModule ( ) throw () |
357 | | { |
358 | | } |
359 | | |
360 | | Magick::ErrorMonitor::ErrorMonitor ( const std::string& what_ ) |
361 | 0 | : Error(what_) |
362 | 0 | { |
363 | 0 | } |
364 | | |
365 | | /*virtual*/ Magick::ErrorMonitor::~ErrorMonitor ( ) throw () |
366 | | { |
367 | | } |
368 | | |
369 | | Magick::ErrorOption::ErrorOption ( const std::string& what_ ) |
370 | 7.19k | : Error(what_) |
371 | 7.19k | { |
372 | 7.19k | } |
373 | | |
374 | | /*virtual*/ Magick::ErrorOption::~ErrorOption ( ) throw () |
375 | | { |
376 | | } |
377 | | |
378 | | Magick::ErrorRegistry::ErrorRegistry ( const std::string& what_ ) |
379 | 0 | : Error(what_) |
380 | 0 | { |
381 | 0 | } |
382 | | |
383 | | /*virtual*/ Magick::ErrorRegistry::~ErrorRegistry ( ) throw () |
384 | | { |
385 | | } |
386 | | |
387 | | Magick::ErrorResourceLimit::ErrorResourceLimit ( const std::string& what_ ) |
388 | 15.7k | : Error(what_) |
389 | 15.7k | { |
390 | 15.7k | } |
391 | | |
392 | | /*virtual*/ Magick::ErrorResourceLimit::~ErrorResourceLimit ( ) throw () |
393 | | { |
394 | | } |
395 | | |
396 | | Magick::ErrorStream::ErrorStream ( const std::string& what_ ) |
397 | 0 | : Error(what_) |
398 | 0 | { |
399 | 0 | } |
400 | | |
401 | | /*virtual*/ Magick::ErrorStream::~ErrorStream ( ) throw () |
402 | | { |
403 | | } |
404 | | |
405 | | Magick::ErrorType::ErrorType ( const std::string& what_ ) |
406 | 1.24k | : Error(what_) |
407 | 1.24k | { |
408 | 1.24k | } |
409 | | |
410 | | /*virtual*/ Magick::ErrorType::~ErrorType ( ) throw () |
411 | | { |
412 | | } |
413 | | |
414 | | Magick::ErrorXServer::ErrorXServer ( const std::string& what_ ) |
415 | 0 | : Error(what_) |
416 | 0 | { |
417 | 0 | } |
418 | | |
419 | | /*virtual*/ Magick::ErrorXServer::~ErrorXServer ( ) throw () |
420 | | { |
421 | | } |
422 | | |
423 | | namespace Magick |
424 | | { |
425 | | // |
426 | | |
427 | | // Throw appropriate C++ exception with type matching 'severity_' using pre-formatted 'message_' |
428 | | #if __cplusplus >= 201103L |
429 | | [[ noreturn ]] |
430 | | #endif |
431 | | static void throwExceptionWithMessage( const ExceptionType severity_, |
432 | | const std::string &message_ ); |
433 | | |
434 | | // Format ExceptionInfo into a message string |
435 | | static std::string FormatExceptionInfoToMessage( const ExceptionInfo &exception_ ); |
436 | | |
437 | | } // namespace Magick |
438 | | |
439 | | // Throw appropriate C++ exception with type matching 'severity_' using pre-formatted 'message_' |
440 | | #if __cplusplus >= 201103L |
441 | | [[ noreturn ]] |
442 | | #endif |
443 | | static void Magick::throwExceptionWithMessage( const ExceptionType severity_, |
444 | | const std::string &message_ ) |
445 | 491k | { |
446 | 491k | switch ( severity_ ) |
447 | 491k | { |
448 | | // Warnings |
449 | 0 | case ResourceLimitWarning : |
450 | 0 | throw WarningResourceLimit( message_ ); |
451 | 0 | case TypeWarning : |
452 | 0 | throw WarningType( message_ ); |
453 | 61 | case OptionWarning : |
454 | 61 | throw WarningOption( message_ ); |
455 | 0 | case DelegateWarning : |
456 | 0 | throw WarningDelegate( message_ ); |
457 | 0 | case MissingDelegateWarning : |
458 | 0 | throw WarningMissingDelegate( message_ ); |
459 | 6.64k | case CorruptImageWarning : |
460 | 6.64k | throw WarningCorruptImage( message_ ); |
461 | 0 | case FileOpenWarning : |
462 | 0 | throw WarningFileOpen( message_ ); |
463 | 0 | case BlobWarning : |
464 | 0 | throw WarningBlob ( message_ ); |
465 | 0 | case StreamWarning : |
466 | 0 | throw WarningStream ( message_ ); |
467 | 0 | case CacheWarning : |
468 | 0 | throw WarningCache ( message_ ); |
469 | 11.5k | case CoderWarning : |
470 | 11.5k | throw WarningCoder ( message_ ); |
471 | 0 | case ModuleWarning : |
472 | 0 | throw WarningModule( message_ ); |
473 | 0 | case DrawWarning : |
474 | 0 | throw WarningDraw( message_ ); |
475 | 0 | case ImageWarning : |
476 | 0 | throw WarningImage( message_ ); |
477 | 0 | case XServerWarning : |
478 | 0 | throw WarningXServer( message_ ); |
479 | 0 | case MonitorWarning : |
480 | 0 | throw WarningMonitor( message_ ); |
481 | 0 | case RegistryWarning : |
482 | 0 | throw WarningRegistry( message_ ); |
483 | 0 | case ConfigureWarning : |
484 | 0 | throw WarningConfigure( message_ ); |
485 | | // Errors |
486 | 15.7k | case ResourceLimitError : |
487 | 15.7k | case ResourceLimitFatalError : |
488 | 15.7k | throw ErrorResourceLimit( message_ ); |
489 | 1.24k | case TypeError : |
490 | 1.24k | case TypeFatalError : |
491 | 1.24k | throw ErrorType( message_ ); |
492 | 7.19k | case OptionError : |
493 | 7.19k | case OptionFatalError : |
494 | 7.19k | throw ErrorOption( message_ ); |
495 | 17.6k | case DelegateError : |
496 | 17.6k | case DelegateFatalError : |
497 | 17.6k | throw ErrorDelegate( message_ ); |
498 | 44 | case MissingDelegateError : |
499 | 44 | case MissingDelegateFatalError : |
500 | 44 | throw ErrorMissingDelegate( message_ ); |
501 | 321k | case CorruptImageError : |
502 | 321k | case CorruptImageFatalError : |
503 | 321k | throw ErrorCorruptImage( message_ ); |
504 | 179 | case FileOpenError : |
505 | 179 | case FileOpenFatalError : |
506 | 179 | throw ErrorFileOpen( message_ ); |
507 | 1.61k | case BlobError : |
508 | 1.61k | case BlobFatalError : |
509 | 1.61k | throw ErrorBlob ( message_ ); |
510 | 0 | case StreamError : |
511 | 0 | case StreamFatalError : |
512 | 0 | throw ErrorStream ( message_ ); |
513 | 185 | case CacheError : |
514 | 185 | case CacheFatalError : |
515 | 185 | throw ErrorCache ( message_ ); |
516 | 100k | case CoderError : |
517 | 100k | case CoderFatalError : |
518 | 100k | throw ErrorCoder ( message_ ); |
519 | 0 | case ModuleError : |
520 | 0 | case ModuleFatalError : |
521 | 0 | throw ErrorModule ( message_ ); |
522 | 7.18k | case DrawError : |
523 | 7.18k | case DrawFatalError : |
524 | 7.18k | throw ErrorDraw ( message_ ); |
525 | 0 | case ImageError : |
526 | 0 | case ImageFatalError : |
527 | 0 | throw ErrorImage ( message_ ); |
528 | 0 | case XServerError : |
529 | 0 | case XServerFatalError : |
530 | 0 | throw ErrorXServer ( message_ ); |
531 | 0 | case MonitorError : |
532 | 0 | case MonitorFatalError : |
533 | 0 | throw ErrorMonitor ( message_ ); |
534 | 0 | case RegistryError : |
535 | 0 | case RegistryFatalError : |
536 | 0 | throw ErrorRegistry ( message_ ); |
537 | 22 | case ConfigureError : |
538 | 22 | case ConfigureFatalError : |
539 | 22 | throw ErrorConfigure ( message_ ); |
540 | 0 | case UndefinedException : |
541 | 0 | default : |
542 | 0 | throw ErrorUndefined( message_ ); |
543 | 491k | } |
544 | 491k | } |
545 | | |
546 | | // Format ExceptionInfo into a message string for human consumption |
547 | | static std::string Magick::FormatExceptionInfoToMessage( const Magick::ExceptionInfo &exception_ ) |
548 | 491k | { |
549 | | // Format error message GraphicsMagick-style |
550 | 491k | std::string message = SetClientName(0); |
551 | 491k | if ( exception_.reason != 0 ) |
552 | 491k | { |
553 | 491k | message += std::string(": "); |
554 | 491k | message += std::string(exception_.reason); |
555 | 491k | } |
556 | | |
557 | 491k | if ( exception_.description != 0 ) |
558 | 464k | message += " (" + std::string(exception_.description) + ")"; |
559 | | |
560 | 491k | if ( exception_.module != 0) |
561 | 491k | { |
562 | 491k | char line_str[24]; |
563 | 491k | sprintf( line_str, "%lu", exception_.line); |
564 | 491k | message += " reported by " + std::string(exception_.module); |
565 | 491k | message += ":" + std::string(line_str); |
566 | 491k | if ((exception_.function != 0) && strcmp("unknown",exception_.function)) |
567 | 491k | message += " (" + std::string(exception_.function) + ")"; |
568 | 491k | } |
569 | | |
570 | 491k | return message; |
571 | 491k | } |
572 | | |
573 | | // Format and throw C++ exception (always) based on parameterized info. |
574 | | // Suitable for handling hard errors. |
575 | | #if __cplusplus >= 201103L |
576 | | [[ noreturn ]] |
577 | | #endif |
578 | | MagickDLLDecl void Magick::throwExceptionAlways( const ExceptionType severity_, |
579 | | const char* reason_, |
580 | | const char* description_) |
581 | 0 | { |
582 | 0 | Magick::ExceptionInfo exception; |
583 | | |
584 | | // Initialize the ExceptionInfo structure |
585 | 0 | GetExceptionInfo( &exception ); |
586 | | |
587 | | // Populate the ExceptionInfo structure |
588 | 0 | ThrowException2( &exception, severity_, reason_, description_ ); |
589 | | |
590 | | // Throw a C++ exception |
591 | | // Format error message GraphicsMagick-style |
592 | 0 | std::string message = FormatExceptionInfoToMessage( exception ); |
593 | | |
594 | | // Release ExceptionInfo resources |
595 | 0 | DestroyExceptionInfo( &exception ); |
596 | | |
597 | | // Throw appropriate C++ exception with type matching 'severity_' |
598 | | // using pre-formatted 'message_' |
599 | 0 | throwExceptionWithMessage(severity_, message ); |
600 | 0 | } |
601 | | |
602 | | // Format and throw C++ exception based on parameterized info if |
603 | | // severity_ is not UndefinedException. This is used for both Warning |
604 | | // and Error cases. |
605 | | MagickDLLDecl void Magick::throwExceptionExplicit( const ExceptionType severity_, |
606 | | const char* reason_, |
607 | | const char* description_) |
608 | 0 | { |
609 | | // Just return if there is no reported error |
610 | 0 | if ( severity_ == UndefinedException ) |
611 | 0 | return; |
612 | | |
613 | | // Throw appropriate C++ exception with type matching 'severity_' |
614 | | // using pre-formatted 'message_' |
615 | 0 | throwExceptionAlways(severity_, reason_, description_ ); |
616 | 0 | } |
617 | | |
618 | | // Throw C++ exception based on ExceptionInfo unless |
619 | | // exception_.severity is not UndefinedException or if quiet_ == true |
620 | | // and exception_.severity < ErrorException |
621 | | // |
622 | | // The exception_ argument is restored to the default state prior to |
623 | | // throwing C++ exception. |
624 | | MagickDLLDecl void Magick::throwException( ExceptionInfo &exception_, |
625 | | const bool quiet_) |
626 | 1.96M | { |
627 | | // Just return if there is no reported error |
628 | 1.96M | if ( exception_.severity == UndefinedException ) |
629 | 1.47M | return; |
630 | | |
631 | | // Format error message GraphicsMagick-style |
632 | 491k | std::string message = FormatExceptionInfoToMessage( exception_ ); |
633 | | |
634 | | // Save severity |
635 | 491k | ExceptionType severity = exception_.severity; |
636 | | |
637 | | // Release ExceptionInfo resources |
638 | 491k | DestroyExceptionInfo( &exception_ ); |
639 | | |
640 | | // Restore ExceptionInfo to defaults |
641 | 491k | GetExceptionInfo( &exception_ ); |
642 | | |
643 | 491k | if ((quiet_) && (severity < ErrorException)) |
644 | 0 | return; |
645 | | |
646 | | // Throw appropriate C++ exception with type matching 'severity_' |
647 | | // using pre-formatted 'message_' |
648 | 491k | throwExceptionWithMessage(severity, message ); |
649 | 491k | } |