cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | // This may look like C code, but it is really -*- C++ -*- |
| 2 | // |
| 3 | // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003 |
| 4 | // |
| 5 | // Implementation of Exception and derived classes |
| 6 | // |
| 7 | |
| 8 | #define MAGICKCORE_IMPLEMENTATION 1 |
| 9 | #define MAGICK_PLUSPLUS_IMPLEMENTATION 1 |
| 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 | : _what(what_) |
| 23 | { |
| 24 | } |
| 25 | |
| 26 | // Copy constructor |
| 27 | Magick::Exception::Exception( const Magick::Exception& original_ ) |
| 28 | : exception(original_), _what(original_._what) |
| 29 | { |
| 30 | } |
| 31 | |
| 32 | // Assignment operator |
| 33 | Magick::Exception& Magick::Exception::operator= (const Magick::Exception& original_ ) |
| 34 | { |
| 35 | if(this != &original_) |
| 36 | { |
| 37 | this->_what = original_._what; |
| 38 | } |
| 39 | return *this; |
| 40 | } |
| 41 | |
| 42 | // Return message string |
| 43 | /*virtual*/ const char* Magick::Exception::what( ) const throw() |
| 44 | { |
| 45 | return _what.c_str(); |
| 46 | } |
| 47 | |
| 48 | /* Destructor */ |
| 49 | /*virtual*/ Magick::Exception::~Exception ( ) throw () |
| 50 | { |
| 51 | } |
| 52 | |
| 53 | // |
| 54 | // Warnings |
| 55 | // |
| 56 | |
| 57 | Magick::Warning::Warning ( const std::string& what_ ) |
| 58 | : Exception(what_) |
| 59 | { |
| 60 | } |
| 61 | |
| 62 | Magick::WarningUndefined::WarningUndefined ( const std::string& what_ ) |
| 63 | : Warning(what_) |
| 64 | { |
| 65 | } |
| 66 | |
| 67 | Magick::WarningBlob::WarningBlob ( const std::string& what_ ) |
| 68 | : Warning(what_) |
| 69 | { |
| 70 | } |
| 71 | |
| 72 | Magick::WarningCache::WarningCache ( const std::string& what_ ) |
| 73 | : Warning(what_) |
| 74 | { |
| 75 | } |
| 76 | |
| 77 | Magick::WarningCoder::WarningCoder ( const std::string& what_ ) |
| 78 | : Warning(what_) |
| 79 | { |
| 80 | } |
| 81 | |
| 82 | Magick::WarningConfigure::WarningConfigure ( const std::string& what_ ) |
| 83 | : Warning(what_) |
| 84 | { |
| 85 | } |
| 86 | |
| 87 | Magick::WarningCorruptImage::WarningCorruptImage ( const std::string& what_ ) |
| 88 | : Warning(what_) |
| 89 | { |
| 90 | } |
| 91 | |
| 92 | Magick::WarningDelegate::WarningDelegate ( const std::string& what_ ) |
| 93 | : Warning(what_) |
| 94 | { |
| 95 | } |
| 96 | |
| 97 | Magick::WarningDraw::WarningDraw ( const std::string& what_ ) |
| 98 | : Warning(what_) |
| 99 | { |
| 100 | } |
| 101 | |
| 102 | Magick::WarningFileOpen::WarningFileOpen ( const std::string& what_ ) |
| 103 | : Warning(what_) |
| 104 | { |
| 105 | } |
| 106 | |
| 107 | Magick::WarningImage::WarningImage ( const std::string& what_ ) |
| 108 | : Warning(what_) |
| 109 | { |
| 110 | } |
| 111 | |
| 112 | Magick::WarningMissingDelegate::WarningMissingDelegate ( const std::string& what_ ) |
| 113 | : Warning(what_) |
| 114 | { |
| 115 | } |
| 116 | |
| 117 | Magick::WarningModule::WarningModule ( const std::string& what_ ) |
| 118 | : Warning(what_) |
| 119 | { |
| 120 | } |
| 121 | |
| 122 | Magick::WarningMonitor::WarningMonitor ( const std::string& what_ ) |
| 123 | : Warning(what_) |
| 124 | { |
| 125 | } |
| 126 | |
| 127 | Magick::WarningOption::WarningOption ( const std::string& what_ ) |
| 128 | : Warning(what_) |
| 129 | { |
| 130 | } |
| 131 | |
| 132 | Magick::WarningRegistry::WarningRegistry ( const std::string& what_ ) |
| 133 | : Warning(what_) |
| 134 | { |
| 135 | } |
| 136 | |
| 137 | Magick::WarningResourceLimit::WarningResourceLimit ( const std::string& what_ ) |
| 138 | : Warning(what_) |
| 139 | { |
| 140 | } |
| 141 | |
| 142 | Magick::WarningStream::WarningStream ( const std::string& what_ ) |
| 143 | : Warning(what_) |
| 144 | { |
| 145 | } |
| 146 | |
| 147 | Magick::WarningType::WarningType ( const std::string& what_ ) |
| 148 | : Warning(what_) |
| 149 | { |
| 150 | } |
| 151 | |
| 152 | Magick::WarningXServer::WarningXServer ( const std::string& what_ ) |
| 153 | : Warning(what_) |
| 154 | { |
| 155 | } |
| 156 | |
| 157 | // |
| 158 | // Errors |
| 159 | // |
| 160 | |
| 161 | Magick::Error::Error ( const std::string& what_ ) |
| 162 | : Exception(what_) |
| 163 | { |
| 164 | } |
| 165 | |
| 166 | Magick::ErrorUndefined::ErrorUndefined ( const std::string& what_ ) |
| 167 | : Error(what_) |
| 168 | { |
| 169 | } |
| 170 | |
| 171 | Magick::ErrorBlob::ErrorBlob ( const std::string& what_ ) |
| 172 | : Error(what_) |
| 173 | { |
| 174 | } |
| 175 | |
| 176 | Magick::ErrorCache::ErrorCache ( const std::string& what_ ) |
| 177 | : Error(what_) |
| 178 | { |
| 179 | } |
| 180 | |
| 181 | Magick::ErrorCoder::ErrorCoder ( const std::string& what_ ) |
| 182 | : Error(what_) |
| 183 | { |
| 184 | } |
| 185 | |
| 186 | Magick::ErrorConfigure::ErrorConfigure ( const std::string& what_ ) |
| 187 | : Error(what_) |
| 188 | { |
| 189 | } |
| 190 | |
| 191 | Magick::ErrorCorruptImage::ErrorCorruptImage ( const std::string& what_ ) |
| 192 | : Error(what_) |
| 193 | { |
| 194 | } |
| 195 | |
| 196 | Magick::ErrorDelegate::ErrorDelegate ( const std::string& what_ ) |
| 197 | : Error(what_) |
| 198 | { |
| 199 | } |
| 200 | |
| 201 | Magick::ErrorDraw::ErrorDraw ( const std::string& what_ ) |
| 202 | : Error(what_) |
| 203 | { |
| 204 | } |
| 205 | |
| 206 | Magick::ErrorFileOpen::ErrorFileOpen ( const std::string& what_ ) |
| 207 | : Error(what_) |
| 208 | { |
| 209 | } |
| 210 | |
| 211 | Magick::ErrorImage::ErrorImage ( const std::string& what_ ) |
| 212 | : Error(what_) |
| 213 | { |
| 214 | } |
| 215 | |
| 216 | Magick::ErrorMissingDelegate::ErrorMissingDelegate ( const std::string& what_ ) |
| 217 | : Error(what_) |
| 218 | { |
| 219 | } |
| 220 | |
| 221 | Magick::ErrorModule::ErrorModule ( const std::string& what_ ) |
| 222 | : Error(what_) |
| 223 | { |
| 224 | } |
| 225 | |
| 226 | Magick::ErrorMonitor::ErrorMonitor ( const std::string& what_ ) |
| 227 | : Error(what_) |
| 228 | { |
| 229 | } |
| 230 | |
| 231 | Magick::ErrorOption::ErrorOption ( const std::string& what_ ) |
| 232 | : Error(what_) |
| 233 | { |
| 234 | } |
| 235 | |
| 236 | Magick::ErrorRegistry::ErrorRegistry ( const std::string& what_ ) |
| 237 | : Error(what_) |
| 238 | { |
| 239 | } |
| 240 | |
| 241 | Magick::ErrorResourceLimit::ErrorResourceLimit ( const std::string& what_ ) |
| 242 | : Error(what_) |
| 243 | { |
| 244 | } |
| 245 | |
| 246 | Magick::ErrorStream::ErrorStream ( const std::string& what_ ) |
| 247 | : Error(what_) |
| 248 | { |
| 249 | } |
| 250 | |
| 251 | Magick::ErrorType::ErrorType ( const std::string& what_ ) |
| 252 | : Error(what_) |
| 253 | { |
| 254 | } |
| 255 | |
| 256 | Magick::ErrorXServer::ErrorXServer ( const std::string& what_ ) |
| 257 | : Error(what_) |
| 258 | { |
| 259 | } |
| 260 | |
| 261 | // Format and throw exception |
cristy | af1dd25 | 2011-09-07 19:04:02 +0000 | [diff] [blame] | 262 | MagickPPExport void Magick::throwExceptionExplicit( const ExceptionType severity_, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 263 | const char* reason_, |
| 264 | const char* description_) |
| 265 | { |
| 266 | // Just return if there is no reported error |
| 267 | if ( severity_ == UndefinedException ) |
| 268 | return; |
| 269 | |
| 270 | ExceptionInfo exception; |
| 271 | |
| 272 | GetExceptionInfo( &exception ); |
| 273 | ThrowException( &exception, severity_, reason_, description_ ); |
| 274 | throwException( exception ); |
| 275 | (void) DestroyExceptionInfo( &exception ); |
| 276 | } |
| 277 | |
| 278 | // Throw C++ exception |
cristy | af1dd25 | 2011-09-07 19:04:02 +0000 | [diff] [blame] | 279 | MagickPPExport void Magick::throwException( ExceptionInfo &exception_ ) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 280 | { |
| 281 | // Just return if there is no reported error |
| 282 | if ( exception_.severity == UndefinedException ) |
| 283 | return; |
| 284 | |
| 285 | // Format error message ImageMagick-style |
| 286 | std::string message = SetClientName(0); |
| 287 | if ( exception_.reason != 0 ) |
| 288 | { |
| 289 | message += std::string(": "); |
| 290 | message += std::string(exception_.reason); |
| 291 | } |
| 292 | |
| 293 | if ( exception_.description != 0 ) |
| 294 | message += " (" + std::string(exception_.description) + ")"; |
| 295 | |
| 296 | ExceptionType severity = exception_.severity; |
| 297 | MagickBooleanType relinquish = exception_.relinquish; |
| 298 | DestroyExceptionInfo( &exception_ ); |
| 299 | if (relinquish) |
| 300 | GetExceptionInfo( &exception_ ); |
| 301 | |
| 302 | switch ( severity ) |
| 303 | { |
| 304 | // Warnings |
| 305 | case ResourceLimitWarning : |
| 306 | throw WarningResourceLimit( message ); |
| 307 | case TypeWarning : |
| 308 | throw WarningType( message ); |
| 309 | case OptionWarning : |
| 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 ); |
| 319 | case BlobWarning : |
| 320 | throw WarningBlob ( message ); |
| 321 | case StreamWarning : |
| 322 | throw WarningStream ( message ); |
| 323 | case CacheWarning : |
| 324 | throw WarningCache ( message ); |
| 325 | case CoderWarning : |
| 326 | throw WarningCoder ( message ); |
| 327 | case ModuleWarning : |
| 328 | throw WarningModule( message ); |
| 329 | case DrawWarning : |
| 330 | throw WarningDraw( message ); |
| 331 | case ImageWarning : |
| 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 ); |
| 341 | // Errors |
| 342 | case ResourceLimitError : |
| 343 | case ResourceLimitFatalError : |
| 344 | throw ErrorResourceLimit( message ); |
| 345 | case TypeError : |
| 346 | case TypeFatalError : |
| 347 | throw ErrorType( message ); |
| 348 | case OptionError : |
| 349 | case OptionFatalError : |
| 350 | throw ErrorOption( message ); |
| 351 | case DelegateError : |
| 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 ); |
| 360 | case FileOpenError : |
| 361 | case FileOpenFatalError : |
| 362 | throw ErrorFileOpen( message ); |
| 363 | case BlobError : |
| 364 | case BlobFatalError : |
| 365 | throw ErrorBlob ( message ); |
| 366 | case StreamError : |
| 367 | case StreamFatalError : |
| 368 | throw ErrorStream ( message ); |
| 369 | case CacheError : |
| 370 | case CacheFatalError : |
| 371 | throw ErrorCache ( message ); |
| 372 | case CoderError : |
| 373 | case CoderFatalError : |
| 374 | throw ErrorCoder ( message ); |
| 375 | case ModuleError : |
| 376 | case ModuleFatalError : |
| 377 | throw ErrorModule ( message ); |
| 378 | case DrawError : |
| 379 | case DrawFatalError : |
| 380 | throw ErrorDraw ( message ); |
| 381 | case ImageError : |
| 382 | case ImageFatalError : |
| 383 | throw ErrorImage ( message ); |
| 384 | case XServerError : |
| 385 | case XServerFatalError : |
| 386 | throw ErrorXServer ( message ); |
| 387 | case MonitorError : |
| 388 | case MonitorFatalError : |
| 389 | throw ErrorMonitor ( message ); |
| 390 | case RegistryError : |
| 391 | case RegistryFatalError : |
| 392 | throw ErrorRegistry ( message ); |
| 393 | case ConfigureError : |
| 394 | case ConfigureFatalError : |
| 395 | throw ErrorConfigure ( message ); |
| 396 | case UndefinedException : |
| 397 | default : |
| 398 | throw ErrorUndefined( message ); |
| 399 | } |
| 400 | |
| 401 | } |