1 // This may look like C code, but it is really -*- C++ -*-
3 // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003
5 // Implementation of Exception and derived classes
8 #define MAGICKCORE_IMPLEMENTATION 1
9 #define MAGICK_PLUSPLUS_IMPLEMENTATION 1
11 #include "Magick++/Include.h"
18 #include "Magick++/Exception.h"
20 // Construct with message string
21 Magick::Exception::Exception( const std::string& what_ )
28 Magick::Exception::Exception( const Magick::Exception& original_ )
29 : exception(original_),
30 _what(original_._what)
34 // Assignment operator
35 Magick::Exception& Magick::Exception::operator= (const Magick::Exception& original_ )
37 if(this != &original_)
39 this->_what = original_._what;
44 // Return message string
45 /*virtual*/ const char* Magick::Exception::what( ) const throw()
51 /*virtual*/ Magick::Exception::~Exception ( ) throw ()
59 Magick::Warning::Warning ( const std::string& what_ )
64 /*virtual*/ Magick::Warning::~Warning ( ) throw ()
68 Magick::WarningUndefined::WarningUndefined ( const std::string& what_ )
73 /*virtual*/ Magick::WarningUndefined::~WarningUndefined ( ) throw ()
77 Magick::WarningBlob::WarningBlob ( const std::string& what_ )
82 /*virtual*/ Magick::WarningBlob::~WarningBlob ( ) throw ()
86 Magick::WarningCache::WarningCache ( const std::string& what_ )
91 /*virtual*/ Magick::WarningCache::~WarningCache ( ) throw ()
95 Magick::WarningCoder::WarningCoder ( const std::string& what_ )
100 /*virtual*/ Magick::WarningCoder::~WarningCoder ( ) throw ()
104 Magick::WarningConfigure::WarningConfigure ( const std::string& what_ )
109 /*virtual*/ Magick::WarningConfigure::~WarningConfigure ( ) throw ()
113 Magick::WarningCorruptImage::WarningCorruptImage ( const std::string& what_ )
118 /*virtual*/ Magick::WarningCorruptImage::~WarningCorruptImage ( ) throw ()
122 Magick::WarningDelegate::WarningDelegate ( const std::string& what_ )
127 /*virtual*/ Magick::WarningDelegate::~WarningDelegate ( ) throw ()
131 Magick::WarningDraw::WarningDraw ( const std::string& what_ )
136 /*virtual*/ Magick::WarningDraw::~WarningDraw ( ) throw ()
140 Magick::WarningFileOpen::WarningFileOpen ( const std::string& what_ )
145 /*virtual*/ Magick::WarningFileOpen::~WarningFileOpen ( ) throw ()
149 Magick::WarningImage::WarningImage ( const std::string& what_ )
154 /*virtual*/ Magick::WarningImage::~WarningImage ( ) throw ()
158 Magick::WarningMissingDelegate::WarningMissingDelegate ( const std::string& what_ )
163 /*virtual*/ Magick::WarningMissingDelegate::~WarningMissingDelegate ( ) throw ()
167 Magick::WarningModule::WarningModule ( const std::string& what_ )
172 /*virtual*/ Magick::WarningModule::~WarningModule ( ) throw ()
176 Magick::WarningMonitor::WarningMonitor ( const std::string& what_ )
181 /*virtual*/ Magick::WarningMonitor::~WarningMonitor ( ) throw ()
185 Magick::WarningOption::WarningOption ( const std::string& what_ )
190 /*virtual*/ Magick::WarningOption::~WarningOption ( ) throw ()
194 Magick::WarningRegistry::WarningRegistry ( const std::string& what_ )
199 /*virtual*/ Magick::WarningRegistry::~WarningRegistry ( ) throw ()
203 Magick::WarningResourceLimit::WarningResourceLimit ( const std::string& what_ )
208 /*virtual*/ Magick::WarningResourceLimit::~WarningResourceLimit ( ) throw ()
212 Magick::WarningStream::WarningStream ( const std::string& what_ )
217 /*virtual*/ Magick::WarningStream::~WarningStream ( ) throw ()
221 Magick::WarningType::WarningType ( const std::string& what_ )
226 /*virtual*/ Magick::WarningType::~WarningType ( ) throw ()
230 Magick::WarningXServer::WarningXServer ( const std::string& what_ )
235 /*virtual*/ Magick::WarningXServer::~WarningXServer ( ) throw ()
243 Magick::Error::Error ( const std::string& what_ )
248 /*virtual*/ Magick::Error::~Error ( ) throw ()
252 Magick::ErrorUndefined::ErrorUndefined ( const std::string& what_ )
257 /*virtual*/ Magick::ErrorUndefined::~ErrorUndefined ( ) throw ()
261 Magick::ErrorBlob::ErrorBlob ( const std::string& what_ )
266 /*virtual*/ Magick::ErrorBlob::~ErrorBlob ( ) throw ()
270 Magick::ErrorCache::ErrorCache ( const std::string& what_ )
275 /*virtual*/ Magick::ErrorCache::~ErrorCache ( ) throw ()
279 Magick::ErrorCoder::ErrorCoder ( const std::string& what_ )
284 /*virtual*/ Magick::ErrorCoder::~ErrorCoder ( ) throw ()
288 Magick::ErrorConfigure::ErrorConfigure ( const std::string& what_ )
293 /*virtual*/ Magick::ErrorConfigure::~ErrorConfigure ( ) throw ()
297 Magick::ErrorCorruptImage::ErrorCorruptImage ( const std::string& what_ )
302 /*virtual*/ Magick::ErrorCorruptImage::~ErrorCorruptImage ( ) throw ()
306 Magick::ErrorDelegate::ErrorDelegate ( const std::string& what_ )
311 /*virtual*/ Magick::ErrorDelegate::~ErrorDelegate ( ) throw ()
315 Magick::ErrorDraw::ErrorDraw ( const std::string& what_ )
320 /*virtual*/ Magick::ErrorDraw::~ErrorDraw ( ) throw ()
324 Magick::ErrorFileOpen::ErrorFileOpen ( const std::string& what_ )
329 /*virtual*/ Magick::ErrorFileOpen::~ErrorFileOpen ( ) throw ()
333 Magick::ErrorImage::ErrorImage ( const std::string& what_ )
338 /*virtual*/ Magick::ErrorImage::~ErrorImage ( ) throw ()
342 Magick::ErrorMissingDelegate::ErrorMissingDelegate ( const std::string& what_ )
347 /*virtual*/ Magick::ErrorMissingDelegate::~ErrorMissingDelegate ( ) throw ()
351 Magick::ErrorModule::ErrorModule ( const std::string& what_ )
356 /*virtual*/ Magick::ErrorModule::~ErrorModule ( ) throw ()
360 Magick::ErrorMonitor::ErrorMonitor ( const std::string& what_ )
365 /*virtual*/ Magick::ErrorMonitor::~ErrorMonitor ( ) throw ()
369 Magick::ErrorOption::ErrorOption ( const std::string& what_ )
374 /*virtual*/ Magick::ErrorOption::~ErrorOption ( ) throw ()
378 Magick::ErrorRegistry::ErrorRegistry ( const std::string& what_ )
383 /*virtual*/ Magick::ErrorRegistry::~ErrorRegistry ( ) throw ()
387 Magick::ErrorResourceLimit::ErrorResourceLimit ( const std::string& what_ )
392 /*virtual*/ Magick::ErrorResourceLimit::~ErrorResourceLimit ( ) throw ()
396 Magick::ErrorStream::ErrorStream ( const std::string& what_ )
401 /*virtual*/ Magick::ErrorStream::~ErrorStream ( ) throw ()
405 Magick::ErrorType::ErrorType ( const std::string& what_ )
410 /*virtual*/ Magick::ErrorType::~ErrorType ( ) throw ()
414 Magick::ErrorXServer::ErrorXServer ( const std::string& what_ )
419 /*virtual*/ Magick::ErrorXServer::~ErrorXServer ( ) throw ()
423 // Format and throw exception
424 MagickPPExport void Magick::throwExceptionExplicit( const ExceptionType severity_,
426 const char* description_)
428 // Just return if there is no reported error
429 if ( severity_ == UndefinedException )
432 ExceptionInfo exception;
434 GetExceptionInfo( &exception );
435 ThrowException( &exception, severity_, reason_, description_ );
436 throwException( exception );
437 (void) DestroyExceptionInfo( &exception );
440 // Throw C++ exception
441 MagickPPExport void Magick::throwException( ExceptionInfo &exception_ )
443 // Just return if there is no reported error
444 if ( exception_.severity == UndefinedException )
447 // Format error message ImageMagick-style
448 std::string message = SetClientName(0);
449 if ( exception_.reason != 0 )
451 message += std::string(": ");
452 message += std::string(exception_.reason);
455 if ( exception_.description != 0 )
456 message += " (" + std::string(exception_.description) + ")";
458 ExceptionType severity = exception_.severity;
459 MagickBooleanType relinquish = exception_.relinquish;
460 DestroyExceptionInfo( &exception_ );
462 GetExceptionInfo( &exception_ );
467 case ResourceLimitWarning :
468 throw WarningResourceLimit( message );
470 throw WarningType( message );
472 throw WarningOption( message );
473 case DelegateWarning :
474 throw WarningDelegate( message );
475 case MissingDelegateWarning :
476 throw WarningMissingDelegate( message );
477 case CorruptImageWarning :
478 throw WarningCorruptImage( message );
479 case FileOpenWarning :
480 throw WarningFileOpen( message );
482 throw WarningBlob ( message );
484 throw WarningStream ( message );
486 throw WarningCache ( message );
488 throw WarningCoder ( message );
490 throw WarningModule( message );
492 throw WarningDraw( message );
494 throw WarningImage( message );
495 case XServerWarning :
496 throw WarningXServer( message );
497 case MonitorWarning :
498 throw WarningMonitor( message );
499 case RegistryWarning :
500 throw WarningRegistry( message );
501 case ConfigureWarning :
502 throw WarningConfigure( message );
504 case ResourceLimitError :
505 case ResourceLimitFatalError :
506 throw ErrorResourceLimit( message );
508 case TypeFatalError :
509 throw ErrorType( message );
511 case OptionFatalError :
512 throw ErrorOption( message );
514 case DelegateFatalError :
515 throw ErrorDelegate( message );
516 case MissingDelegateError :
517 case MissingDelegateFatalError :
518 throw ErrorMissingDelegate( message );
519 case CorruptImageError :
520 case CorruptImageFatalError :
521 throw ErrorCorruptImage( message );
523 case FileOpenFatalError :
524 throw ErrorFileOpen( message );
526 case BlobFatalError :
527 throw ErrorBlob ( message );
529 case StreamFatalError :
530 throw ErrorStream ( message );
532 case CacheFatalError :
533 throw ErrorCache ( message );
535 case CoderFatalError :
536 throw ErrorCoder ( message );
538 case ModuleFatalError :
539 throw ErrorModule ( message );
541 case DrawFatalError :
542 throw ErrorDraw ( message );
544 case ImageFatalError :
545 throw ErrorImage ( message );
547 case XServerFatalError :
548 throw ErrorXServer ( message );
550 case MonitorFatalError :
551 throw ErrorMonitor ( message );
553 case RegistryFatalError :
554 throw ErrorRegistry ( message );
555 case ConfigureError :
556 case ConfigureFatalError :
557 throw ErrorConfigure ( message );
558 case UndefinedException :
560 throw ErrorUndefined( message );