]> granicus.if.org Git - imagemagick/blob - Magick++/lib/Exception.cpp
(no commit message)
[imagemagick] / Magick++ / lib / Exception.cpp
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   : std::exception(),
23     _what(what_)
24 {
25 }
26
27 // Copy constructor
28 Magick::Exception::Exception( const Magick::Exception& original_ )
29   : exception(original_),
30     _what(original_._what)
31 {
32 }
33
34 // Assignment operator
35 Magick::Exception& Magick::Exception::operator= (const Magick::Exception& original_ )
36 {
37   if(this != &original_)
38     {
39       this->_what = original_._what;
40     }
41   return *this;
42 }
43
44 // Return message string
45 /*virtual*/ const char* Magick::Exception::what( ) const throw()
46 {
47   return _what.c_str();
48 }
49
50 /* Destructor */
51 /*virtual*/ Magick::Exception::~Exception ( ) throw ()
52 {
53 }
54
55 //
56 // Warnings
57 //
58
59 Magick::Warning::Warning ( const std::string& what_ )
60   : Exception(what_)
61 {
62 }
63
64 /*virtual*/ Magick::Warning::~Warning ( ) throw ()
65 {
66 }
67
68 Magick::WarningUndefined::WarningUndefined ( const std::string& what_ )
69   : Warning(what_)
70 {
71 }
72
73 /*virtual*/ Magick::WarningUndefined::~WarningUndefined ( ) throw ()
74 {
75 }
76
77 Magick::WarningBlob::WarningBlob ( const std::string& what_ )
78   : Warning(what_)
79 {
80 }
81
82 /*virtual*/ Magick::WarningBlob::~WarningBlob ( ) throw ()
83 {
84 }
85
86 Magick::WarningCache::WarningCache ( const std::string& what_ )
87   : Warning(what_)
88 {
89 }
90
91 /*virtual*/ Magick::WarningCache::~WarningCache ( ) throw ()
92 {
93 }
94
95 Magick::WarningCoder::WarningCoder ( const std::string& what_ )
96   : Warning(what_)
97 {
98 }
99
100 /*virtual*/ Magick::WarningCoder::~WarningCoder ( ) throw ()
101 {
102 }
103
104 Magick::WarningConfigure::WarningConfigure ( const std::string& what_ )
105   : Warning(what_)
106 {
107 }
108
109 /*virtual*/ Magick::WarningConfigure::~WarningConfigure ( ) throw ()
110 {
111 }
112
113 Magick::WarningCorruptImage::WarningCorruptImage ( const std::string& what_ )
114   : Warning(what_)
115 {
116 }
117
118 /*virtual*/ Magick::WarningCorruptImage::~WarningCorruptImage ( ) throw ()
119 {
120 }
121
122 Magick::WarningDelegate::WarningDelegate ( const std::string& what_ )
123   : Warning(what_)
124 {
125 }
126
127 /*virtual*/ Magick::WarningDelegate::~WarningDelegate ( ) throw ()
128 {
129 }
130
131 Magick::WarningDraw::WarningDraw ( const std::string& what_ )
132   : Warning(what_)
133 {
134 }
135
136 /*virtual*/ Magick::WarningDraw::~WarningDraw ( ) throw ()
137 {
138 }
139
140 Magick::WarningFileOpen::WarningFileOpen ( const std::string& what_ )
141   : Warning(what_)
142 {
143 }
144
145 /*virtual*/ Magick::WarningFileOpen::~WarningFileOpen ( ) throw ()
146 {
147 }
148
149 Magick::WarningImage::WarningImage ( const std::string& what_ )
150   : Warning(what_)
151 {
152 }
153
154 /*virtual*/ Magick::WarningImage::~WarningImage ( ) throw ()
155 {
156 }
157
158 Magick::WarningMissingDelegate::WarningMissingDelegate ( const std::string& what_ )
159   : Warning(what_)
160 {
161 }
162
163 /*virtual*/ Magick::WarningMissingDelegate::~WarningMissingDelegate ( ) throw ()
164 {
165 }
166
167 Magick::WarningModule::WarningModule ( const std::string& what_ )
168   : Warning(what_)
169 {
170 }
171
172 /*virtual*/ Magick::WarningModule::~WarningModule ( ) throw ()
173 {
174 }
175
176 Magick::WarningMonitor::WarningMonitor ( const std::string& what_ )
177   : Warning(what_)
178 {
179 }
180
181 /*virtual*/ Magick::WarningMonitor::~WarningMonitor ( ) throw ()
182 {
183 }
184
185 Magick::WarningOption::WarningOption ( const std::string& what_ )
186   : Warning(what_)
187 {
188 }
189
190 /*virtual*/ Magick::WarningOption::~WarningOption ( ) throw ()
191 {
192 }
193
194 Magick::WarningRegistry::WarningRegistry ( const std::string& what_ )
195   : Warning(what_)
196 {
197 }
198
199 /*virtual*/ Magick::WarningRegistry::~WarningRegistry ( ) throw ()
200 {
201 }
202
203 Magick::WarningResourceLimit::WarningResourceLimit ( const std::string& what_ )
204   : Warning(what_)
205 {
206 }
207
208 /*virtual*/ Magick::WarningResourceLimit::~WarningResourceLimit ( ) throw ()
209 {
210 }
211
212 Magick::WarningStream::WarningStream ( const std::string& what_ )
213   : Warning(what_)
214 {
215 }
216
217 /*virtual*/ Magick::WarningStream::~WarningStream ( ) throw ()
218 {
219 }
220
221 Magick::WarningType::WarningType ( const std::string& what_ )
222   : Warning(what_)
223 {
224 }
225
226 /*virtual*/ Magick::WarningType::~WarningType ( ) throw ()
227 {
228 }
229
230 Magick::WarningXServer::WarningXServer ( const std::string& what_ )
231   : Warning(what_)
232 {
233 }
234
235 /*virtual*/ Magick::WarningXServer::~WarningXServer ( ) throw ()
236 {
237 }
238
239 //
240 // Errors
241 //
242
243 Magick::Error::Error ( const std::string& what_ )
244   : Exception(what_)
245 {
246 }
247
248 /*virtual*/ Magick::Error::~Error ( ) throw ()
249 {
250 }
251
252 Magick::ErrorUndefined::ErrorUndefined ( const std::string& what_ )
253   : Error(what_)
254 {
255 }
256
257 /*virtual*/ Magick::ErrorUndefined::~ErrorUndefined ( ) throw ()
258 {
259 }
260
261 Magick::ErrorBlob::ErrorBlob ( const std::string& what_ )
262   : Error(what_)
263 {
264 }
265
266 /*virtual*/ Magick::ErrorBlob::~ErrorBlob ( ) throw ()
267 {
268 }
269
270 Magick::ErrorCache::ErrorCache ( const std::string& what_ )
271   : Error(what_)
272 {
273 }
274
275 /*virtual*/ Magick::ErrorCache::~ErrorCache ( ) throw ()
276 {
277 }
278
279 Magick::ErrorCoder::ErrorCoder ( const std::string& what_ )
280   : Error(what_)
281 {
282 }
283
284 /*virtual*/ Magick::ErrorCoder::~ErrorCoder ( ) throw ()
285 {
286 }
287
288 Magick::ErrorConfigure::ErrorConfigure ( const std::string& what_ )
289   : Error(what_)
290 {
291 }
292
293 /*virtual*/ Magick::ErrorConfigure::~ErrorConfigure ( ) throw ()
294 {
295 }
296
297 Magick::ErrorCorruptImage::ErrorCorruptImage ( const std::string& what_ )
298   : Error(what_)
299 {
300 }
301
302 /*virtual*/ Magick::ErrorCorruptImage::~ErrorCorruptImage ( ) throw ()
303 {
304 }
305
306 Magick::ErrorDelegate::ErrorDelegate ( const std::string& what_ )
307   : Error(what_)
308 {
309 }
310
311 /*virtual*/ Magick::ErrorDelegate::~ErrorDelegate ( ) throw ()
312 {
313 }
314
315 Magick::ErrorDraw::ErrorDraw ( const std::string& what_ )
316   : Error(what_)
317 {
318 }
319
320 /*virtual*/ Magick::ErrorDraw::~ErrorDraw ( ) throw ()
321 {
322 }
323
324 Magick::ErrorFileOpen::ErrorFileOpen ( const std::string& what_ )
325   : Error(what_)
326 {
327 }
328
329 /*virtual*/ Magick::ErrorFileOpen::~ErrorFileOpen ( ) throw ()
330 {
331 }
332
333 Magick::ErrorImage::ErrorImage ( const std::string& what_ )
334   : Error(what_)
335 {
336 }
337
338 /*virtual*/ Magick::ErrorImage::~ErrorImage ( ) throw ()
339 {
340 }
341
342 Magick::ErrorMissingDelegate::ErrorMissingDelegate ( const std::string& what_ )
343   : Error(what_)
344 {
345 }
346
347 /*virtual*/ Magick::ErrorMissingDelegate::~ErrorMissingDelegate ( ) throw ()
348 {
349 }
350
351 Magick::ErrorModule::ErrorModule ( const std::string& what_ )
352   : Error(what_)
353 {
354 }
355
356 /*virtual*/ Magick::ErrorModule::~ErrorModule ( ) throw ()
357 {
358 }
359
360 Magick::ErrorMonitor::ErrorMonitor ( const std::string& what_ )
361   : Error(what_)
362 {
363 }
364
365 /*virtual*/ Magick::ErrorMonitor::~ErrorMonitor ( ) throw ()
366 {
367 }
368
369 Magick::ErrorOption::ErrorOption ( const std::string& what_ )
370   : Error(what_)
371 {
372 }
373
374 /*virtual*/ Magick::ErrorOption::~ErrorOption ( ) throw ()
375 {
376 }
377
378 Magick::ErrorRegistry::ErrorRegistry ( const std::string& what_ )
379   : Error(what_)
380 {
381 }
382
383 /*virtual*/ Magick::ErrorRegistry::~ErrorRegistry ( ) throw ()
384 {
385 }
386
387 Magick::ErrorResourceLimit::ErrorResourceLimit ( const std::string& what_ )
388   : Error(what_)
389 {
390 }
391
392 /*virtual*/ Magick::ErrorResourceLimit::~ErrorResourceLimit ( ) throw ()
393 {
394 }
395
396 Magick::ErrorStream::ErrorStream ( const std::string& what_ )
397   : Error(what_)
398 {
399 }
400
401 /*virtual*/ Magick::ErrorStream::~ErrorStream ( ) throw ()
402 {
403 }
404
405 Magick::ErrorType::ErrorType ( const std::string& what_ )
406   : Error(what_)
407 {
408 }
409
410 /*virtual*/ Magick::ErrorType::~ErrorType ( ) throw ()
411 {
412 }
413
414 Magick::ErrorXServer::ErrorXServer ( const std::string& what_ )
415   : Error(what_)
416 {
417 }
418
419 /*virtual*/ Magick::ErrorXServer::~ErrorXServer ( ) throw ()
420 {
421 }
422
423 // Format and throw exception
424 MagickPPExport void Magick::throwExceptionExplicit( const ExceptionType severity_,
425                                                    const char* reason_,
426                                                    const char* description_)
427 {
428   // Just return if there is no reported error
429   if ( severity_ == UndefinedException )
430     return;
431
432   ExceptionInfo exception;
433
434   GetExceptionInfo( &exception );
435   ThrowException( &exception, severity_, reason_, description_ );
436   throwException( exception );
437   (void) DestroyExceptionInfo( &exception );
438 }
439
440 // Throw C++ exception
441 MagickPPExport void Magick::throwException( ExceptionInfo &exception_ )
442 {
443   // Just return if there is no reported error
444   if ( exception_.severity == UndefinedException )
445     return;
446
447   // Format error message ImageMagick-style
448   std::string message = SetClientName(0);
449   if ( exception_.reason != 0 )
450     {
451       message += std::string(": ");
452       message += std::string(exception_.reason);
453     }
454
455   if ( exception_.description != 0 )
456     message += " (" + std::string(exception_.description) + ")";
457
458   ExceptionType severity = exception_.severity;
459   MagickBooleanType relinquish = exception_.relinquish;
460   DestroyExceptionInfo( &exception_ );
461   if (relinquish)
462     GetExceptionInfo( &exception_ );
463
464   switch ( severity )
465     {
466       // Warnings
467     case ResourceLimitWarning :
468       throw WarningResourceLimit( message );
469     case TypeWarning :
470       throw WarningType( message );
471     case OptionWarning :
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 );
481     case BlobWarning :
482       throw WarningBlob ( message );
483     case StreamWarning :
484       throw WarningStream ( message );
485     case CacheWarning :
486       throw WarningCache ( message );
487     case CoderWarning :
488       throw WarningCoder ( message );
489     case ModuleWarning :
490       throw WarningModule( message );
491     case DrawWarning :
492       throw WarningDraw( message );
493     case ImageWarning :
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 );
503       // Errors
504     case ResourceLimitError :
505     case ResourceLimitFatalError :
506       throw ErrorResourceLimit( message );
507     case TypeError :
508     case TypeFatalError :
509       throw ErrorType( message );
510     case OptionError :
511     case OptionFatalError :
512       throw ErrorOption( message );
513     case DelegateError :
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 );
522     case FileOpenError :
523     case FileOpenFatalError :
524       throw ErrorFileOpen( message );
525     case BlobError :
526     case BlobFatalError :
527       throw ErrorBlob ( message );
528     case StreamError :
529     case StreamFatalError :
530       throw ErrorStream ( message );
531     case CacheError :
532     case CacheFatalError :
533       throw ErrorCache ( message );
534     case CoderError :
535     case CoderFatalError :
536       throw ErrorCoder ( message );
537     case ModuleError :
538     case ModuleFatalError :
539       throw ErrorModule ( message );
540     case DrawError :
541     case DrawFatalError :
542       throw ErrorDraw ( message );
543     case ImageError :
544     case ImageFatalError :
545       throw ErrorImage ( message );
546     case XServerError :
547     case XServerFatalError :
548       throw ErrorXServer ( message );
549     case MonitorError :
550     case MonitorFatalError :
551       throw ErrorMonitor ( message );
552     case RegistryError :
553     case RegistryFatalError :
554       throw ErrorRegistry ( message );
555     case ConfigureError :
556     case ConfigureFatalError :
557       throw ErrorConfigure ( message );
558     case UndefinedException :
559     default :
560       throw ErrorUndefined( message );
561     }
562
563 }