root / ImageMagick / trunk / magick / exception.c

Revision 11223, 37.5 kB (checked in by cristy, 3 months ago)
Line 
1/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3%                                                                             %
4%                                                                             %
5%                                                                             %
6%        EEEEE  X   X   CCCC  EEEEE  PPPP  TTTTT  IIIII   OOO   N   N         %
7%        E       X X   C      E      P   P   T      I    O   O  NN  N         %
8%        EEE      X    C      EEE    PPPP    T      I    O   O  N N N         %
9%        E       X X   C      E      P       T      I    O   O  N  NN         %
10%        EEEEE   X  X   CCCC  EEEEE  P       T    IIIII   OOO   N   N         %
11%                                                                             %
12%                                                                             %
13%                       ImageMagick Exception Methods                         %
14%                                                                             %
15%                             Software Design                                 %
16%                               John Cristy                                   %
17%                                July 1993                                    %
18%                                                                             %
19%                                                                             %
20%  Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization      %
21%  dedicated to making software imaging solutions freely available.           %
22%                                                                             %
23%  You may not use this file except in compliance with the License.  You may  %
24%  obtain a copy of the License at                                            %
25%                                                                             %
26%    http://www.imagemagick.org/script/license.php                            %
27%                                                                             %
28%  Unless required by applicable law or agreed to in writing, software        %
29%  distributed under the License is distributed on an "AS IS" BASIS,          %
30%  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
31%  See the License for the specific language governing permissions and        %
32%  limitations under the License.                                             %
33%                                                                             %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36%
37%
38*/
39
40/*
41  Include declarations.
42*/
43#include "magick/studio.h"
44#include "magick/client.h"
45#include "magick/exception.h"
46#include "magick/exception-private.h"
47#include "magick/hashmap.h"
48#include "magick/locale_.h"
49#include "magick/log.h"
50#include "magick/magick.h"
51#include "magick/memory_.h"
52#include "magick/string_.h"
53#include "magick/utility.h"
54
55/*
56  Forward declarations.
57*/
58#if defined(__cplusplus) || defined(c_plusplus)
59extern "C" {
60#endif
61
62static void
63  DefaultErrorHandler(const ExceptionType,const char *,const char *),
64  DefaultFatalErrorHandler(const ExceptionType,const char *,const char *),
65  DefaultWarningHandler(const ExceptionType,const char *,const char *);
66
67#if defined(__cplusplus) || defined(c_plusplus)
68}
69#endif
70
71/*
72  Global declarations.
73*/
74static ErrorHandler
75  error_handler = DefaultErrorHandler;
76
77static FatalErrorHandler
78  fatal_error_handler = DefaultFatalErrorHandler;
79
80static WarningHandler
81  warning_handler = DefaultWarningHandler;
82
83/*
84%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85%                                                                             %
86%                                                                             %
87%                                                                             %
88%   A c q u i r e E x c e p t i o n I n f o                                   %
89%                                                                             %
90%                                                                             %
91%                                                                             %
92%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93%
94%  AcquireExceptionInfo() allocates the ExceptionInfo structure.
95%
96%  The format of the AcquireExceptionInfo method is:
97%
98%      ExceptionInfo *AcquireExceptionInfo(void)
99%
100*/
101MagickExport ExceptionInfo *AcquireExceptionInfo(void)
102{
103  ExceptionInfo
104    *exception;
105
106  exception=(ExceptionInfo *) AcquireMagickMemory(sizeof(*exception));
107  if (exception == (ExceptionInfo *) NULL)
108    ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
109  GetExceptionInfo(exception);
110  exception->relinquish=MagickTrue;
111  return(exception);
112}
113
114/*
115%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116%                                                                             %
117%                                                                             %
118%                                                                             %
119%   C l e a r M a g i c k E x c e p t i o n                                   %
120%                                                                             %
121%                                                                             %
122%                                                                             %
123%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124%
125%  ClearMagickException() clears any exception that may not have been caught
126%  yet.
127%
128%  The format of the ClearMagickException method is:
129%
130%      ClearMagickException(ExceptionInfo *exception)
131%
132%  A description of each parameter follows:
133%
134%    o exception: the exception info.
135%
136*/
137
138static void *DestroyExceptionElement(void *exception)
139{
140  register ExceptionInfo
141    *p;
142
143  p=(ExceptionInfo *) exception;
144  if (p->reason != (char *) NULL)
145    p->reason=DestroyString(p->reason);
146  if (p->description != (char *) NULL)
147    p->description=DestroyString(p->description);
148  p=(ExceptionInfo *) RelinquishMagickMemory(p);
149  return((void *) NULL);
150}
151
152MagickExport void ClearMagickException(ExceptionInfo *exception)
153{
154  register ExceptionInfo
155    *p;
156
157  assert(exception != (ExceptionInfo *) NULL);
158  assert(exception->signature == MagickSignature);
159  AcquireSemaphoreInfo(&exception->semaphore);
160  p=(ExceptionInfo *) RemoveLastElementFromLinkedList((LinkedListInfo *)
161    exception->exceptions);
162  while (p != (ExceptionInfo *) NULL)
163  {
164    (void) DestroyExceptionElement(p);
165    p=(ExceptionInfo *) RemoveLastElementFromLinkedList((LinkedListInfo *)
166      exception->exceptions);
167  }
168  exception->severity=UndefinedException;
169  exception->reason=(char *) NULL;
170  exception->description=(char *) NULL;
171  RelinquishSemaphoreInfo(exception->semaphore);
172  errno=0;
173}
174
175/*
176%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177%                                                                             %
178%                                                                             %
179%                                                                             %
180%   C a t c h E x c e p t i o n                                               %
181%                                                                             %
182%                                                                             %
183%                                                                             %
184%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185%
186%  CatchException() returns if no exceptions is found otherwise it reports
187%  the exception as a warning, error, or fatal depending on the severity.
188%
189%  The format of the CatchException method is:
190%
191%      CatchException(ExceptionInfo *exception)
192%
193%  A description of each parameter follows:
194%
195%    o exception: the exception info.
196%
197*/
198MagickExport void CatchException(ExceptionInfo *exception)
199{
200  register const ExceptionInfo
201    *p;
202
203  assert(exception != (ExceptionInfo *) NULL);
204  assert(exception->signature == MagickSignature);
205  AcquireSemaphoreInfo(&exception->semaphore);
206  ResetLinkedListIterator((LinkedListInfo *) exception->exceptions);
207  p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *)
208    exception->exceptions);
209  while (p != (const ExceptionInfo *) NULL)
210  {
211    if ((p->severity >= WarningException) && (p->severity < ErrorException))
212      MagickWarning(p->severity,p->reason,p->description);
213    if ((p->severity >= ErrorException) && (p->severity < FatalErrorException))
214      MagickError(p->severity,p->reason,p->description);
215    if (exception->severity >= FatalErrorException)
216      MagickFatalError(p->severity,p->reason,p->description);
217    p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *)
218      exception->exceptions);
219  }
220  RelinquishSemaphoreInfo(exception->semaphore);
221  ClearMagickException(exception);
222}
223
224/*
225%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226%                                                                             %
227%                                                                             %
228%                                                                             %
229+   D e f a u l t E r r o r H a n d l e r                                     %
230%                                                                             %
231%                                                                             %
232%                                                                             %
233%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234%
235%  DefaultErrorHandler() displays an error reason.
236%
237%  The format of the DefaultErrorHandler method is:
238%
239%      void MagickError(const ExceptionType severity,const char *reason,
240%        const char *description)
241%
242%  A description of each parameter follows:
243%
244%    o severity: Specifies the numeric error category.
245%
246%    o reason: Specifies the reason to display before terminating the
247%      program.
248%
249%    o description: Specifies any description to the reason.
250%
251*/
252static void DefaultErrorHandler(const ExceptionType magick_unused(severity),
253  const char *reason,const char *description)
254{
255  if (reason == (char *) NULL)
256    return;
257  (void) fprintf(stderr,"%s: %s",GetClientName(),reason);
258  if (description != (char *) NULL)
259    (void) fprintf(stderr," (%s)",description);
260  (void) fprintf(stderr,".\n");
261  (void) fflush(stderr);
262}
263
264/*
265%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
266%                                                                             %
267%                                                                             %
268%                                                                             %
269+   D e f a u l t F a t a l E r r o r H a n d l e r                           %
270%                                                                             %
271%                                                                             %
272%                                                                             %
273%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
274%
275%  DefaultFatalErrorHandler() displays an error reason and then terminates the
276%  program.
277%
278%  The format of the DefaultFatalErrorHandler method is:
279%
280%      void MagickFatalError(const ExceptionType severity,const char *reason,
281%        const char *description)
282%
283%  A description of each parameter follows:
284%
285%    o severity: Specifies the numeric error category.
286%
287%    o reason: Specifies the reason to display before terminating the
288%      program.
289%
290%    o description: Specifies any description to the reason.
291%
292*/
293static void DefaultFatalErrorHandler(const ExceptionType magick_unused(severity),
294  const char *reason,const char *description)
295{
296  if (reason == (char *) NULL)
297    return;
298  (void) fprintf(stderr,"%s: %s",GetClientName(),reason);
299  if (description != (char *) NULL)
300    (void) fprintf(stderr," (%s)",description);
301  (void) fprintf(stderr,".\n");
302  (void) fflush(stderr);
303  MagickCoreTerminus();
304  exit(1);
305}
306
307/*
308%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
309%                                                                             %
310%                                                                             %
311%                                                                             %
312+   D e f a u l t W a r n i n g H a n d l e r                                 %
313%                                                                             %
314%                                                                             %
315%                                                                             %
316%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
317%
318%  DefaultWarningHandler() displays a warning reason.
319%
320%  The format of the DefaultWarningHandler method is:
321%
322%      void DefaultWarningHandler(const ExceptionType warning,
323%        const char *reason,const char *description)
324%
325%  A description of each parameter follows:
326%
327%    o warning: Specifies the numeric warning category.
328%
329%    o reason: Specifies the reason to display before terminating the
330%      program.
331%
332%    o description: Specifies any description to the reason.
333%
334*/
335static void DefaultWarningHandler(const ExceptionType magick_unused(severity),
336  const char *reason,const char *description)
337{
338  if (reason == (char *) NULL)
339    return;
340  (void) fprintf(stderr,"%s: %s",GetClientName(),reason);
341  if (description != (char *) NULL)
342    (void) fprintf(stderr," (%s)",description);
343  (void) fprintf(stderr,".\n");
344  (void) fflush(stderr);
345}
346
347/*
348%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
349%                                                                             %
350%                                                                             %
351%                                                                             %
352%   D e s t r o y E x c e p t i o n I n f o                                   %
353%                                                                             %
354%                                                                             %
355%                                                                             %
356%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
357%
358%  DestroyExceptionInfo() deallocates memory associated with an exception.
359%
360%  The format of the DestroyExceptionInfo method is:
361%
362%      ExceptionInfo *DestroyExceptionInfo(ExceptionInfo *exception)
363%
364%  A description of each parameter follows:
365%
366%    o exception: the exception info.
367%
368*/
369MagickExport ExceptionInfo *DestroyExceptionInfo(ExceptionInfo *exception)
370{
371  MagickBooleanType
372    relinquish;
373
374  assert(exception != (ExceptionInfo *) NULL);
375  assert(exception->signature == MagickSignature);
376  AcquireSemaphoreInfo(&exception->semaphore);
377  exception->severity=UndefinedException;
378  if (exception->exceptions != (void *) NULL)
379    exception->exceptions=(void *) DestroyLinkedList((LinkedListInfo *)
380      exception->exceptions,DestroyExceptionElement);
381  relinquish=exception->relinquish;
382  if (exception->relinquish != MagickFalse)
383    exception->signature=(~MagickSignature);
384  RelinquishSemaphoreInfo(exception->semaphore);
385  DestroySemaphoreInfo(&exception->semaphore);
386  if (relinquish != MagickFalse)
387    exception=(ExceptionInfo *) RelinquishMagickMemory(exception);
388  return(exception);
389}
390
391/*
392%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
393%                                                                             %
394%                                                                             %
395%                                                                             %
396%   G e t E x c e p t i o n I n f o                                           %
397%                                                                             %
398%                                                                             %
399%                                                                             %
400%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
401%
402%  GetExceptionInfo() initializes an exception to default values.
403%
404%  The format of the GetExceptionInfo method is:
405%
406%      GetExceptionInfo(ExceptionInfo *exception)
407%
408%  A description of each parameter follows:
409%
410%    o exception: the exception info.
411%
412*/
413MagickExport void GetExceptionInfo(ExceptionInfo *exception)
414{
415  assert(exception != (ExceptionInfo *) NULL);
416  (void) ResetMagickMemory(exception,0,sizeof(*exception));
417  exception->severity=UndefinedException;
418  exception->exceptions=(void *) NewLinkedList(0);
419  exception->signature=MagickSignature;
420}
421
422/*
423%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
424%                                                                             %
425%                                                                             %
426%                                                                             %
427%   G e t E x c e p t i o n M e s s a g e                                     %
428%                                                                             %
429%                                                                             %
430%                                                                             %
431%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
432%
433%  GetExceptionMessage() returns the error message defined by the specified
434%  error code.
435%
436%  The format of the GetExceptionMessage method is:
437%
438%      char *GetExceptionMessage(const int error_code)
439%
440%  A description of each parameter follows:
441%
442%    o error_code: the error code.
443%
444*/
445MagickExport char *GetExceptionMessage(const int error_code)
446{
447  return(ConstantString(strerror(error_code)));
448}
449
450/*
451%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
452%                                                                             %
453%                                                                             %
454%                                                                             %
455%   G e t L o c a l e E x c e p t i o n M e s s a g e                         %
456%                                                                             %
457%                                                                             %
458%                                                                             %
459%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
460%
461%  GetLocaleExceptionMessage() converts a enumerated exception severity and tag
462%  to a message in the current locale.
463%
464%  The format of the GetLocaleExceptionMessage method is:
465%
466%      const char *GetLocaleExceptionMessage(const ExceptionType severity,
467%        const char *tag)
468%
469%  A description of each parameter follows:
470%
471%    o severity: the severity of the exception.
472%
473%    o tag: the message tag.
474%
475*/
476
477static const char *ExceptionSeverityToTag(const ExceptionType severity)
478{
479  switch (severity)
480  {
481    case ResourceLimitWarning: return("Resource/Limit/Warning/");
482    case TypeWarning: return("Type/Warning/");
483    case OptionWarning: return("Option/Warning/");
484    case DelegateWarning: return("Delegate/Warning/");
485    case MissingDelegateWarning: return("Missing/Delegate/Warning/");
486    case CorruptImageWarning: return("Corrupt/Image/Warning/");
487    case FileOpenWarning: return("File/Open/Warning/");
488    case BlobWarning: return("Blob/Warning/");
489    case StreamWarning: return("Stream/Warning/");
490    case CacheWarning: return("Cache/Warning/");
491    case CoderWarning: return("Coder/Warning/");
492    case ModuleWarning: return("Module/Warning/");
493    case DrawWarning: return("Draw/Warning/");
494    case ImageWarning: return("Image/Warning/");
495    case WandWarning: return("Wand/Warning/");
496    case XServerWarning: return("XServer/Warning/");
497    case MonitorWarning: return("Monitor/Warning/");
498    case RegistryWarning: return("Registry/Warning/");
499    case ConfigureWarning: return("Configure/Warning/");
500    case ResourceLimitError: return("Resource/Limit/Error/");
501    case TypeError: return("Type/Error/");
502    case OptionError: return("Option/Error/");
503    case DelegateError: return("Delegate/Error/");
504    case MissingDelegateError: return("Missing/Delegate/Error/");
505    case CorruptImageError: return("Corrupt/Image/Error/");
506    case FileOpenError: return("File/Open/Error/");
507    case BlobError: return("Blob/Error/");
508    case StreamError: return("Stream/Error/");
509    case CacheError: return("Cache/Error/");
510    case CoderError: return("Coder/Error/");
511    case ModuleError: return("Module/Error/");
512    case DrawError: return("Draw/Error/");
513    case ImageError: return("Image/Error/");
514    case WandError: return("Wand/Error/");
515    case XServerError: return("XServer/Error/");
516    case MonitorError: return("Monitor/Error/");
517    case RegistryError: return("Registry/Error/");
518    case ConfigureError: return("Configure/Error/");
519    case ResourceLimitFatalError: return("Resource/Limit/FatalError/");
520    case TypeFatalError: return("Type/FatalError/");
521    case OptionFatalError: return("Option/FatalError/");
522    case DelegateFatalError: return("Delegate/FatalError/");
523    case MissingDelegateFatalError: return("Missing/Delegate/FatalError/");
524    case CorruptImageFatalError: return("Corrupt/Image/FatalError/");
525    case FileOpenFatalError: return("File/Open/FatalError/");
526    case BlobFatalError: return("Blob/FatalError/");
527    case StreamFatalError: return("Stream/FatalError/");
528    case CacheFatalError: return("Cache/FatalError/");
529    case CoderFatalError: return("Coder/FatalError/");
530    case ModuleFatalError: return("Module/FatalError/");
531    case DrawFatalError: return("Draw/FatalError/");
532    case ImageFatalError: return("Image/FatalError/");
533    case WandFatalError: return("Wand/FatalError/");
534    case XServerFatalError: return("XServer/FatalError/");
535    case MonitorFatalError: return("Monitor/FatalError/");
536    case RegistryFatalError: return("Registry/FatalError/");
537    case ConfigureFatalError: return("Configure/FatalError/");
538    default: break;
539  }
540  return("");
541}
542
543MagickExport const char *GetLocaleExceptionMessage(const ExceptionType severity,
544  const char *tag)
545{
546  char
547    message[MaxTextExtent];
548
549  const char
550    *locale_message;
551
552  assert(tag != (const char *) NULL);
553  (void) FormatMagickString(message,MaxTextExtent,"Exception/%s%s",
554    ExceptionSeverityToTag(severity),tag);
555  locale_message=GetLocaleMessage(message);
556  if (locale_message == (const char *) NULL)
557    return(tag);
558  if (locale_message == message)
559    return(tag);
560  return(locale_message);
561}
562
563/*
564%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
565%                                                                             %
566%                                                                             %
567%                                                                             %
568%   I n h e r i t E x c e p t i o n                                           %
569%                                                                             %
570%                                                                             %
571%                                                                             %
572%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
573%
574%  InheritException() inherits an exception from a related exception.
575%
576%  The format of the InheritException method is:
577%
578%      InheritException(ExceptionInfo *exception,const ExceptionInfo *relative)
579%
580%  A description of each parameter follows:
581%
582%    o exception: the exception info.
583%
584%    o relative: the related exception info.
585%
586*/
587MagickExport void InheritException(ExceptionInfo *exception,
588  const ExceptionInfo *relative)
589{
590  register const ExceptionInfo
591    *p;
592
593  assert(exception != (ExceptionInfo *) NULL);
594  assert(exception->signature == MagickSignature);
595  assert(relative != (ExceptionInfo *) NULL);
596  assert(relative->signature == MagickSignature);
597  AcquireSemaphoreInfo(&exception->semaphore);
598  ResetLinkedListIterator((LinkedListInfo *) relative->exceptions);
599  p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *)
600    relative->exceptions);
601  while (p != (const ExceptionInfo *) NULL)
602  {
603    (void) ThrowException(exception,p->severity,p->reason,p->description);
604    p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *)
605      relative->exceptions);
606  }
607  RelinquishSemaphoreInfo(exception->semaphore);
608}
609
610/*
611%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
612%                                                                             %
613%                                                                             %
614%                                                                             %
615%   M a g i c k E r r o r                                                     %
616%                                                                             %
617%                                                                             %
618%                                                                             %
619%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
620%
621%  MagickError() calls the exception handler methods with an error reason.
622%
623%  The format of the MagickError method is:
624%
625%      void MagickError(const ExceptionType error,const char *reason,
626%        const char *description)
627%
628%  A description of each parameter follows:
629%
630%    o exception: Specifies the numeric error category.
631%
632%    o reason: Specifies the reason to display before terminating the
633%      program.
634%
635%    o description: Specifies any description to the reason.
636%
637*/
638MagickExport void MagickError(const ExceptionType error,const char *reason,
639  const char *description)
640{
641  if (error_handler != (ErrorHandler) NULL)
642    (*error_handler)(error,reason,description);
643}
644
645/*
646%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
647%                                                                             %
648%                                                                             %
649%                                                                             %
650%   M a g i c k F a t al E r r o r                                            %
651%                                                                             %
652%                                                                             %
653%                                                                             %
654%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
655%
656%  MagickFatalError() calls the fatal exception handler methods with an error
657%  reason.
658%
659%  The format of the MagickError method is:
660%
661%      void MagickFatalError(const ExceptionType error,const char *reason,
662%        const char *description)
663%
664%  A description of each parameter follows:
665%
666%    o exception: Specifies the numeric error category.
667%
668%    o reason: Specifies the reason to display before terminating the
669%      program.
670%
671%    o description: Specifies any description to the reason.
672%
673*/
674MagickExport void MagickFatalError(const ExceptionType error,const char *reason,
675  const char *description)
676{
677  if (fatal_error_handler != (ErrorHandler) NULL)
678    (*fatal_error_handler)(error,reason,description);
679}
680
681/*
682%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
683%                                                                             %
684%                                                                             %
685%                                                                             %
686%   M a g i c k W a r n i n g                                                 %
687%                                                                             %
688%                                                                             %
689%                                                                             %
690%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
691%
692%  MagickWarning() calls the warning handler methods with a warning reason.
693%
694%  The format of the MagickWarning method is:
695%
696%      void MagickWarning(const ExceptionType warning,const char *reason,
697%        const char *description)
698%
699%  A description of each parameter follows:
700%
701%    o warning: the warning severity.
702%
703%    o reason: Define the reason for the warning.
704%
705%    o description: Describe the warning.
706%
707*/
708MagickExport void MagickWarning(const ExceptionType warning,const char *reason,
709  const char *description)
710{
711  if (warning_handler != (WarningHandler) NULL)
712    (*warning_handler)(warning,reason,description);
713}
714
715/*
716%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
717%                                                                             %
718%                                                                             %
719%                                                                             %
720%   S e t E r r o r H a n d l e r                                             %
721%                                                                             %
722%                                                                             %
723%                                                                             %
724%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
725%
726%  SetErrorHandler() sets the exception handler to the specified method
727%  and returns the previous exception handler.
728%
729%  The format of the SetErrorHandler method is:
730%
731%      ErrorHandler SetErrorHandler(ErrorHandler handler)
732%
733%  A description of each parameter follows:
734%
735%    o handler: the method to handle errors.
736%
737*/
738MagickExport ErrorHandler SetErrorHandler(ErrorHandler handler)
739{
740  ErrorHandler
741    previous_handler;
742
743  previous_handler=error_handler;
744  error_handler=handler;
745  return(previous_handler);
746}
747
748/*
749%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
750%                                                                             %
751%                                                                             %
752%                                                                             %
753%   S e t F a t a l E r r o r H a n d l e r                                   %
754%                                                                             %
755%                                                                             %
756%                                                                             %
757%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
758%
759%  SetFatalErrorHandler() sets the fatal exception handler to the specified
760%  method and returns the previous fatal exception handler.
761%
762%  The format of the SetErrorHandler method is:
763%
764%      ErrorHandler SetErrorHandler(ErrorHandler handler)
765%
766%  A description of each parameter follows:
767%
768%    o handler: the method to handle errors.
769%
770*/
771MagickExport FatalErrorHandler SetFatalErrorHandler(FatalErrorHandler handler)
772{
773  FatalErrorHandler
774    previous_handler;
775
776  previous_handler=fatal_error_handler;
777  fatal_error_handler=handler;
778  return(previous_handler);
779}
780
781/*
782%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
783%                                                                             %
784%                                                                             %
785%                                                                             %
786%   S e t W a r n i n g H a n d l e r                                         %
787%                                                                             %
788%                                                                             %
789%                                                                             %
790%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
791%
792%  SetWarningHandler() sets the warning handler to the specified method
793%  and returns the previous warning handler.
794%
795%  The format of the SetWarningHandler method is:
796%
797%      ErrorHandler SetWarningHandler(ErrorHandler handler)
798%
799%  A description of each parameter follows:
800%
801%    o handler: the method to handle warnings.
802%
803*/
804MagickExport WarningHandler SetWarningHandler(WarningHandler handler)
805{
806  WarningHandler
807    previous_handler;
808
809  previous_handler=warning_handler;
810  warning_handler=handler;
811  return(previous_handler);
812}
813
814/*
815%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
816%                                                                             %
817%                                                                             %
818%                                                                             %
819%   T h r o w E x c e p t i o n                                               %
820%                                                                             %
821%                                                                             %