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_ )
27 Magick::Exception::Exception( const Magick::Exception& original_ )
28 : exception(original_), _what(original_._what)
32 // Assignment operator
33 Magick::Exception& Magick::Exception::operator= (const Magick::Exception& original_ )
35 if(this != &original_)
37 this->_what = original_._what;
42 // Return message string
43 /*virtual*/ const char* Magick::Exception::what( ) const throw()
49 /*virtual*/ Magick::Exception::~Exception ( ) throw ()
57 Magick::Warning::Warning ( const std::string& what_ )
62 Magick::WarningUndefined::WarningUndefined ( const std::string& what_ )
67 Magick::WarningBlob::WarningBlob ( const std::string& what_ )
72 Magick::WarningCache::WarningCache ( const std::string& what_ )
77 Magick::WarningCoder::WarningCoder ( const std::string& what_ )
82 Magick::WarningConfigure::WarningConfigure ( const std::string& what_ )
87 Magick::WarningCorruptImage::WarningCorruptImage ( const std::string& what_ )
92 Magick::WarningDelegate::WarningDelegate ( const std::string& what_ )
97 Magick::WarningDraw::WarningDraw ( const std::string& what_ )
102 Magick::WarningFileOpen::WarningFileOpen ( const std::string& what_ )
107 Magick::WarningImage::WarningImage ( const std::string& what_ )
112 Magick::WarningMissingDelegate::WarningMissingDelegate ( const std::string& what_ )
117 Magick::WarningModule::WarningModule ( const std::string& what_ )
122 Magick::WarningMonitor::WarningMonitor ( const std::string& what_ )
127 Magick::WarningOption::WarningOption ( const std::string& what_ )
132 Magick::WarningRegistry::WarningRegistry ( const std::string& what_ )
137 Magick::WarningResourceLimit::WarningResourceLimit ( const std::string& what_ )
142 Magick::WarningStream::WarningStream ( const std::string& what_ )
147 Magick::WarningType::WarningType ( const std::string& what_ )
152 Magick::WarningXServer::WarningXServer ( const std::string& what_ )
161 Magick::Error::Error ( const std::string& what_ )
166 Magick::ErrorUndefined::ErrorUndefined ( const std::string& what_ )
171 Magick::ErrorBlob::ErrorBlob ( const std::string& what_ )
176 Magick::ErrorCache::ErrorCache ( const std::string& what_ )
181 Magick::ErrorCoder::ErrorCoder ( const std::string& what_ )
186 Magick::ErrorConfigure::ErrorConfigure ( const std::string& what_ )
191 Magick::ErrorCorruptImage::ErrorCorruptImage ( const std::string& what_ )
196 Magick::ErrorDelegate::ErrorDelegate ( const std::string& what_ )
201 Magick::ErrorDraw::ErrorDraw ( const std::string& what_ )
206 Magick::ErrorFileOpen::ErrorFileOpen ( const std::string& what_ )
211 Magick::ErrorImage::ErrorImage ( const std::string& what_ )
216 Magick::ErrorMissingDelegate::ErrorMissingDelegate ( const std::string& what_ )
221 Magick::ErrorModule::ErrorModule ( const std::string& what_ )
226 Magick::ErrorMonitor::ErrorMonitor ( const std::string& what_ )
231 Magick::ErrorOption::ErrorOption ( const std::string& what_ )
236 Magick::ErrorRegistry::ErrorRegistry ( const std::string& what_ )
241 Magick::ErrorResourceLimit::ErrorResourceLimit ( const std::string& what_ )
246 Magick::ErrorStream::ErrorStream ( const std::string& what_ )
251 Magick::ErrorType::ErrorType ( const std::string& what_ )
256 Magick::ErrorXServer::ErrorXServer ( const std::string& what_ )
261 // Format and throw exception
262 MagickDLLDecl void Magick::throwExceptionExplicit( const ExceptionType severity_,
264 const char* description_)
266 // Just return if there is no reported error
267 if ( severity_ == UndefinedException )
270 ExceptionInfo exception;
272 GetExceptionInfo( &exception );
273 ThrowException( &exception, severity_, reason_, description_ );
274 throwException( exception );
275 (void) DestroyExceptionInfo( &exception );
278 // Throw C++ exception
279 MagickDLLDecl void Magick::throwException( ExceptionInfo &exception_ )
281 // Just return if there is no reported error
282 if ( exception_.severity == UndefinedException )
285 // Format error message ImageMagick-style
286 std::string message = SetClientName(0);
287 if ( exception_.reason != 0 )
289 message += std::string(": ");
290 message += std::string(exception_.reason);
293 if ( exception_.description != 0 )
294 message += " (" + std::string(exception_.description) + ")";
296 ExceptionType severity = exception_.severity;
297 MagickBooleanType relinquish = exception_.relinquish;
298 DestroyExceptionInfo( &exception_ );
300 GetExceptionInfo( &exception_ );
305 case ResourceLimitWarning :
306 throw WarningResourceLimit( message );
308 throw WarningType( message );
310 throw WarningOption( message );
311 case DelegateWarning :
312 throw WarningDelegate( message );
313 case MissingDelegateWarning :
314 throw WarningMissingDelegate( message );
315 case CorruptImageWarning :
316 throw WarningCorruptImage( message );
317 case FileOpenWarning :
318 throw WarningFileOpen( message );
320 throw WarningBlob ( message );
322 throw WarningStream ( message );
324 throw WarningCache ( message );
326 throw WarningCoder ( message );
328 throw WarningModule( message );
330 throw WarningDraw( message );
332 throw WarningImage( message );
333 case XServerWarning :
334 throw WarningXServer( message );
335 case MonitorWarning :
336 throw WarningMonitor( message );
337 case RegistryWarning :
338 throw WarningRegistry( message );
339 case ConfigureWarning :
340 throw WarningConfigure( message );
342 case ResourceLimitError :
343 case ResourceLimitFatalError :
344 throw ErrorResourceLimit( message );
346 case TypeFatalError :
347 throw ErrorType( message );
349 case OptionFatalError :
350 throw ErrorOption( message );
352 case DelegateFatalError :
353 throw ErrorDelegate( message );
354 case MissingDelegateError :
355 case MissingDelegateFatalError :
356 throw ErrorMissingDelegate( message );
357 case CorruptImageError :
358 case CorruptImageFatalError :
359 throw ErrorCorruptImage( message );
361 case FileOpenFatalError :
362 throw ErrorFileOpen( message );
364 case BlobFatalError :
365 throw ErrorBlob ( message );
367 case StreamFatalError :
368 throw ErrorStream ( message );
370 case CacheFatalError :
371 throw ErrorCache ( message );
373 case CoderFatalError :
374 throw ErrorCoder ( message );
376 case ModuleFatalError :
377 throw ErrorModule ( message );
379 case DrawFatalError :
380 throw ErrorDraw ( message );
382 case ImageFatalError :
383 throw ErrorImage ( message );
385 case XServerFatalError :
386 throw ErrorXServer ( message );
388 case MonitorFatalError :
389 throw ErrorMonitor ( message );
391 case RegistryFatalError :
392 throw ErrorRegistry ( message );
393 case ConfigureError :
394 case ConfigureFatalError :
395 throw ErrorConfigure ( message );
396 case UndefinedException :
398 throw ErrorUndefined( message );