~ubuntu-branches/ubuntu/intrepid/graphicsmagick/intrepid

« back to all changes in this revision

Viewing changes to magick/error.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2006-05-06 16:28:08 UTC
  • Revision ID: james.westby@ubuntu.com-20060506162808-vt2ni3r5nytcszms
Tags: upstream-1.1.7
ImportĀ upstreamĀ versionĀ 1.1.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
% Copyright (C) 2003 GraphicsMagick Group
 
3
% Copyright (C) 2002 ImageMagick Studio
 
4
% Copyright 1991-1999 E. I. du Pont de Nemours and Company
 
5
%
 
6
% This program is covered by multiple licenses, which are described in
 
7
% Copyright.txt. You should have received a copy of Copyright.txt with this
 
8
% package; otherwise see http://www.graphicsmagick.org/www/Copyright.html.
 
9
%
 
10
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
11
%                                                                             %
 
12
%                                                                             %
 
13
%                                                                             %
 
14
%                      EEEEE  RRRR   RRRR   OOO   RRRR                        %
 
15
%                      E      R   R  R   R O   O  R   R                       %
 
16
%                      EEE    RRRR   RRRR  O   O  RRRR                        %
 
17
%                      E      R R    R R   O   O  R R                         %
 
18
%                      EEEEE  R  R   R  R   OOO   R  R                        %
 
19
%                                                                             %
 
20
%                                                                             %
 
21
%                      GraphicsMagick Exception Methods                       %
 
22
%                                                                             %
 
23
%                                                                             %
 
24
%                             Software Design                                 %
 
25
%                               John Cristy                                   %
 
26
%                                July 1993                                    %
 
27
%                                                                             %
 
28
%                                                                             %
 
29
%                                                                             %
 
30
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
31
%
 
32
%
 
33
%
 
34
*/
 
35
 
 
36
/*
 
37
  Include declarations.
 
38
*/
 
39
#include "magick/studio.h"
 
40
#include "magick/magick.h"
 
41
#include "magick/utility.h"
 
42
 
 
43
/*
 
44
  Forward declarations.
 
45
*/
 
46
#if defined(__cplusplus) || defined(c_plusplus)
 
47
extern "C" {
 
48
#endif
 
49
 
 
50
static void
 
51
  DefaultErrorHandler(const ExceptionType,const char *,const char *),
 
52
  DefaultFatalErrorHandler(const ExceptionType,const char *,const char *),
 
53
  DefaultWarningHandler(const ExceptionType,const char *,const char *);
 
54
 
 
55
#if defined(__cplusplus) || defined(c_plusplus)
 
56
}
 
57
#endif
 
58
 
 
59
/*
 
60
  Global declarations.
 
61
*/
 
62
static ErrorHandler
 
63
  error_handler = DefaultErrorHandler;
 
64
 
 
65
static FatalErrorHandler
 
66
  fatal_error_handler = DefaultFatalErrorHandler;
 
67
 
 
68
static WarningHandler
 
69
  warning_handler = DefaultWarningHandler;
 
70
 
 
71
/*
 
72
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
73
%                                                                             %
 
74
%                                                                             %
 
75
%                                                                             %
 
76
%   C a t c h E x c e p t i o n                                               %
 
77
%                                                                             %
 
78
%                                                                             %
 
79
%                                                                             %
 
80
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
81
%
 
82
%  CatchException() returns if no exceptions is found otherwise it reports
 
83
%  the exception as a warning, error, or fatal depending on the severity.
 
84
%
 
85
%  The format of the CatchException method is:
 
86
%
 
87
%      CatchException(const ExceptionInfo *exception)
 
88
%
 
89
%  A description of each parameter follows:
 
90
%
 
91
%    o exception: The exception info.
 
92
%
 
93
%
 
94
*/
 
95
MagickExport void CatchException(const ExceptionInfo *exception)
 
96
{
 
97
  assert(exception != (ExceptionInfo *) NULL);
 
98
  assert(exception->signature == MagickSignature);
 
99
  if (exception->severity == UndefinedException)
 
100
    return;
 
101
  errno=exception->error_number; /* Shabby work-around for parameter limits */
 
102
  if ((exception->severity >= WarningException) &&
 
103
      (exception->severity < ErrorException))
 
104
    {
 
105
      MagickWarning2(exception->severity,exception->reason,
 
106
        exception->description);
 
107
      return;
 
108
    }
 
109
  if ((exception->severity >= ErrorException) &&
 
110
      (exception->severity < FatalErrorException))
 
111
    {
 
112
      MagickError2(exception->severity,exception->reason,exception->description);
 
113
      return;
 
114
    }
 
115
  if (exception->severity >= FatalErrorException)
 
116
    {
 
117
      MagickFatalError2(exception->severity,exception->reason,
 
118
        exception->description);
 
119
      return;
 
120
    }
 
121
}
 
122
 
 
123
/*
 
124
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
125
%                                                                             %
 
126
%                                                                             %
 
127
%                                                                             %
 
128
%  C o p y E x c e p t i o n                                                  %
 
129
%                                                                             %
 
130
%                                                                             %
 
131
%                                                                             %
 
132
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
133
%
 
134
%  CopyException() copies exception data from one ExceptionInfo structure
 
135
%  to another.
 
136
%
 
137
%  The format of the CopyException method is:
 
138
%
 
139
%      void CopyException(ExceptionInfo *copy, const ExceptionInfo *original)
 
140
%
 
141
%  A description of each parameter follows:
 
142
%
 
143
%    o copy: The exception to copy to.
 
144
%
 
145
%    o original: The exception to copy from.
 
146
%
 
147
*/
 
148
MagickExport void CopyException(ExceptionInfo *copy, const ExceptionInfo *original)
 
149
{
 
150
  assert(copy != (ExceptionInfo *) NULL);
 
151
  assert(copy->signature == MagickSignature);
 
152
  assert(original != (ExceptionInfo *) NULL);
 
153
  assert(original->signature == MagickSignature);
 
154
  copy->severity=original->severity;
 
155
  MagickFreeMemory(copy->reason);
 
156
  if (original->reason)
 
157
    copy->reason=AcquireString(original->reason);
 
158
  MagickFreeMemory(copy->description);
 
159
  if (original->description)
 
160
    copy->description=AcquireString(original->description);
 
161
  copy->error_number=original->error_number;
 
162
  MagickFreeMemory(copy->module);
 
163
  if (original->module)
 
164
    copy->module=AcquireString(original->module);
 
165
  MagickFreeMemory(copy->function);
 
166
  if (original->function)
 
167
    copy->function=AcquireString(original->function);
 
168
  copy->line=original->line;
 
169
  return;
 
170
}
 
171
 
 
172
/*
 
173
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
174
%                                                                             %
 
175
%                                                                             %
 
176
%                                                                             %
 
177
+   D e f a u l t E r r o r H a n d l e r                                     %
 
178
%                                                                             %
 
179
%                                                                             %
 
180
%                                                                             %
 
181
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
182
%
 
183
%  Method DefaultErrorHandler displays an error reason.
 
184
%
 
185
%  The format of the DefaultErrorHandler method is:
 
186
%
 
187
%      void DefaultMagickError(const ExceptionType severity,
 
188
%        const char *reason, const char *description)
 
189
%
 
190
%  A description of each parameter follows:
 
191
%
 
192
%    o severity: Specifies the numeric error category.
 
193
%
 
194
%    o reason: Specifies the reason to display before terminating the
 
195
%      program.
 
196
%
 
197
%    o description: Specifies any description to the reason.
 
198
%
 
199
%
 
200
*/
 
201
 
 
202
static const char *GetErrorMessageString(const int error_number)
 
203
{
 
204
  const char
 
205
    *message;
 
206
 
 
207
  message=strerror(error_number);
 
208
  if (message == (const char *) NULL)
 
209
    return("Error number is out of range");
 
210
  return(message);
 
211
}
 
212
 
 
213
static void DefaultErrorHandler(const ExceptionType severity,const char *reason,
 
214
  const char *description)
 
215
{
 
216
  if (reason == (char *) NULL)
 
217
    return;
 
218
 
 
219
  (void) fprintf(stderr,"%.1024s: ",GetClientName());
 
220
  if (strstr(reason,"%s") && description)
 
221
    {
 
222
      /*
 
223
        Reason contains printf specification. %s in reason string
 
224
        is substituted with description.
 
225
      */
 
226
      (void) fprintf(stderr,reason,description);
 
227
    }
 
228
  else
 
229
    {
 
230
      (void) fprintf(stderr,"%.1024s",reason);
 
231
      if (description != (char *) NULL)
 
232
        (void) fprintf(stderr," (%.1024s)",description);
 
233
    }
 
234
  if ((severity != OptionError) && errno)
 
235
    (void) fprintf(stderr," [%.1024s]",GetErrorMessageString(errno));
 
236
  (void) fprintf(stderr,".\n");
 
237
}
 
238
 
 
239
/*
 
240
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
241
%                                                                             %
 
242
%                                                                             %
 
243
%                                                                             %
 
244
+   D e f a u l t F a t a l E r r o r H a n d l e r                           %
 
245
%                                                                             %
 
246
%                                                                             %
 
247
%                                                                             %
 
248
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
249
%
 
250
%  Method DefaultFatalErrorHandler displays an error reason and then terminates
 
251
%  the program.
 
252
%
 
253
%  The format of the DefaultFatalErrorHandler method is:
 
254
%
 
255
%      void DefaultMagickFatalError(const ExceptionType severity,
 
256
%        const char *reason, const char *description)
 
257
%
 
258
%  A description of each parameter follows:
 
259
%
 
260
%    o severity: Specifies the numeric error category.
 
261
%
 
262
%    o reason: Specifies the reason to display before terminating the
 
263
%      program.
 
264
%
 
265
%    o description: Specifies any description to the reason.
 
266
%
 
267
%
 
268
*/
 
269
static void DefaultFatalErrorHandler(const ExceptionType severity,
 
270
  const char *reason,const char *description)
 
271
{
 
272
  if (reason == (char *) NULL)
 
273
    return;
 
274
  (void) fprintf(stderr,"%.1024s: %.1024s",GetClientName(),reason);
 
275
  if (description != (char *) NULL)
 
276
    (void) fprintf(stderr," (%.1024s)",description);
 
277
  if ((severity != OptionError) && errno)
 
278
    (void) fprintf(stderr," [%.1024s]",GetErrorMessageString(errno));
 
279
  (void) fprintf(stderr,".\n");
 
280
  DestroyMagick();
 
281
  Exit(severity);
 
282
}
 
283
 
 
284
/*
 
285
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
286
%                                                                             %
 
287
%                                                                             %
 
288
%                                                                             %
 
289
+   D e f a u l t W a r n i n g H a n d l e r                                 %
 
290
%                                                                             %
 
291
%                                                                             %
 
292
%                                                                             %
 
293
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
294
%
 
295
%  Method DefaultWarningHandler displays a warning reason.
 
296
%
 
297
%  The format of the DefaultWarningHandler method is:
 
298
%
 
299
%      void DefaultWarningHandler(const ExceptionType warning,
 
300
%        const char *reason,const char *description)
 
301
%
 
302
%  A description of each parameter follows:
 
303
%
 
304
%    o warning: Specifies the numeric warning category.
 
305
%
 
306
%    o reason: Specifies the reason to display before terminating the
 
307
%      program.
 
308
%
 
309
%    o description: Specifies any description to the reason.
 
310
%
 
311
%
 
312
*/
 
313
static void DefaultWarningHandler(const ExceptionType severity,
 
314
  const char *reason,const char *description)
 
315
{
 
316
  if (reason == (char *) NULL)
 
317
    return;
 
318
  (void) fprintf(stderr,"%.1024s: %.1024s",GetClientName(),reason);
 
319
  if (description != (char *) NULL)
 
320
    (void) fprintf(stderr," (%.1024s)",description);
 
321
  if ((severity != OptionWarning) && errno)
 
322
    (void) fprintf(stderr," [%.1024s]",GetErrorMessageString(errno));
 
323
  (void) fprintf(stderr,".\n");
 
324
}
 
325
 
 
326
/*
 
327
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
328
%                                                                             %
 
329
%                                                                             %
 
330
%                                                                             %
 
331
%   D e s t r o y E x c e p t i o n I n f o                                   %
 
332
%                                                                             %
 
333
%                                                                             %
 
334
%                                                                             %
 
335
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
336
%
 
337
%  DestroyExceptionInfo() deallocates memory associated with exception.
 
338
%
 
339
%  The format of the DestroyExceptionInfo method is:
 
340
%
 
341
%      void DestroyExceptionInfo(ExceptionInfo *exception)
 
342
%
 
343
%  A description of each parameter follows:
 
344
%
 
345
%    o exception: The exception info.
 
346
%
 
347
%
 
348
*/
 
349
MagickExport void DestroyExceptionInfo(ExceptionInfo *exception)
 
350
{
 
351
  assert(exception != (ExceptionInfo *) NULL);
 
352
  assert(exception->signature == MagickSignature);
 
353
  exception->severity=UndefinedException;
 
354
  MagickFreeMemory(exception->reason);
 
355
  MagickFreeMemory(exception->description);
 
356
  exception->error_number=0;
 
357
  MagickFreeMemory(exception->module);
 
358
  MagickFreeMemory(exception->function);
 
359
  exception->line=0UL;
 
360
  exception->signature=0UL;
 
361
}
 
362
 
 
363
/*
 
364
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
365
%                                                                             %
 
366
%                                                                             %
 
367
%                                                                             %
 
368
%   G e t E x c e p t i o n I n f o                                           %
 
369
%                                                                             %
 
370
%                                                                             %
 
371
%                                                                             %
 
372
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
373
%
 
374
%  GetExceptionInfo() initializes an exception to default values.
 
375
%
 
376
%  The format of the GetExceptionInfo method is:
 
377
%
 
378
%      GetExceptionInfo(ExceptionInfo *exception)
 
379
%
 
380
%  A description of each parameter follows:
 
381
%
 
382
%    o exception: The exception info.
 
383
%
 
384
%
 
385
*/
 
386
MagickExport void GetExceptionInfo(ExceptionInfo *exception)
 
387
{
 
388
  assert(exception != (ExceptionInfo *) NULL);
 
389
  exception->severity=UndefinedException;
 
390
  exception->reason=0;
 
391
  exception->description=0;
 
392
  exception->error_number=0;
 
393
  exception->module=0;
 
394
  exception->function=0;
 
395
  exception->line=0UL;
 
396
  exception->signature=MagickSignature;
 
397
}
 
398
 
 
399
/*
 
400
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
401
%                                                                             %
 
402
%                                                                             %
 
403
%                                                                             %
 
404
%   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                         %
 
405
%                                                                             %
 
406
%                                                                             %
 
407
%                                                                             %
 
408
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
409
%
 
410
%  GetLocaleExceptionMessage() converts a enumerated exception severity and tag
 
411
%  to a message in the current locale.
 
412
%
 
413
%  The format of the GetLocaleExceptionMessage method is:
 
414
%
 
415
%      const char *GetLocaleExceptionMessage(const ExceptionType severity,
 
416
%        const char *tag)
 
417
%
 
418
%  A description of each parameter follows:
 
419
%
 
420
%    o severity: the severity of the exception.
 
421
%
 
422
%    o tag: the message tag.
 
423
%
 
424
%
 
425
%
 
426
*/
 
427
 
 
428
static const char *ExceptionSeverityToTag(const ExceptionType severity)
 
429
{
 
430
  switch (severity)
 
431
  {
 
432
    case UndefinedException: return("Unknown/Error/");
 
433
    case ResourceLimitWarning: return("Resource/Limit/Warning/");
 
434
    case TypeWarning: return("Type/Warning/");
 
435
    case OptionWarning: return("Option/Warning/");
 
436
    case DelegateWarning: return("Delegate/Warning/");
 
437
    case MissingDelegateWarning: return("Missing/Delegate/Warning/");
 
438
    case CorruptImageWarning: return("Corrupt/Image/Warning/");
 
439
    case FileOpenWarning: return("File/Open/Warning/");
 
440
    case BlobWarning: return("Blob/Warning/");
 
441
    case StreamWarning: return("Stream/Warning/");
 
442
    case CacheWarning: return("Cache/Warning/");
 
443
    case CoderWarning: return("Coder/Warning/");
 
444
    case ModuleWarning: return("Module/Warning/");
 
445
    case DrawWarning: return("Draw/Warning/");
 
446
    case ImageWarning: return("Image/Warning/");
 
447
    case WandWarning: return("Wand/Warning/");
 
448
    case XServerWarning: return("XServer/Warning/");
 
449
    case MonitorWarning: return("Monitor/Warning/");
 
450
    case RegistryWarning: return("Registry/Warning/");
 
451
    case ConfigureWarning: return("Configure/Warning/");
 
452
    case ResourceLimitError: return("Resource/Limit/Error/");
 
453
    case TypeError: return("Type/Error/");
 
454
    case OptionError: return("Option/Error/");
 
455
    case DelegateError: return("Delegate/Error/");
 
456
    case MissingDelegateError: return("Missing/Delegate/Error/");
 
457
    case CorruptImageError: return("Corrupt/Image/Error/");
 
458
    case FileOpenError: return("File/Open/Error/");
 
459
    case BlobError: return("Blob/Error/");
 
460
    case StreamError: return("Stream/Error/");
 
461
    case CacheError: return("Cache/Error/");
 
462
    case CoderError: return("Coder/Error/");
 
463
    case ModuleError: return("Module/Error/");
 
464
    case DrawError: return("Draw/Error/");
 
465
    case ImageError: return("Image/Error/");
 
466
    case WandError: return("Wand/Error/");
 
467
    case XServerError: return("XServer/Error/");
 
468
    case MonitorError: return("Monitor/Error/");
 
469
    case RegistryError: return("Registry/Error/");
 
470
    case ConfigureError: return("Configure/Error/");
 
471
    case ResourceLimitFatalError: return("Resource/Limit/FatalError/");
 
472
    case TypeFatalError: return("Type/FatalError/");
 
473
    case OptionFatalError: return("Option/FatalError/");
 
474
    case DelegateFatalError: return("Delegate/FatalError/");
 
475
    case MissingDelegateFatalError: return("Missing/Delegate/FatalError/");
 
476
    case CorruptImageFatalError: return("Corrupt/Image/FatalError/");
 
477
    case FileOpenFatalError: return("File/Open/FatalError/");
 
478
    case BlobFatalError: return("Blob/FatalError/");
 
479
    case StreamFatalError: return("Stream/FatalError/");
 
480
    case CacheFatalError: return("Cache/FatalError/");
 
481
    case CoderFatalError: return("Coder/FatalError/");
 
482
    case ModuleFatalError: return("Module/FatalError/");
 
483
    case DrawFatalError: return("Draw/FatalError/");
 
484
    case ImageFatalError: return("Image/FatalError/");
 
485
    case WandFatalError: return("Wand/FatalError/");
 
486
    case XServerFatalError: return("XServer/FatalError/");
 
487
    case MonitorFatalError: return("Monitor/FatalError/");
 
488
    case RegistryFatalError: return("Registry/FatalError/");
 
489
    case ConfigureFatalError: return("Configure/FatalError/");
 
490
    default: break;
 
491
  }
 
492
  return("");
 
493
}
 
494
 
 
495
MagickExport const char *GetLocaleExceptionMessage(const ExceptionType severity,
 
496
  const char *tag)
 
497
{
 
498
  char
 
499
    message[MaxTextExtent];
 
500
 
 
501
  const char
 
502
    *locale_message;
 
503
 
 
504
  /* protect against NULL lookups */
 
505
  if (tag != (char *) NULL)
 
506
    {
 
507
      /* This is a hack that depends on the fact that tag can never have spaces in
 
508
        them. If a space is found then it means we are being asked to translate a
 
509
        message that has already been translated. A big waste of time. The reason
 
510
        this happens is that messages are translated at the point of an exception
 
511
        and then again when the exception is caught and processed via the default
 
512
        error and warning handlers
 
513
      */
 
514
      if (strrchr(tag, ' '))
 
515
        return tag;
 
516
      FormatString(message,"%.1024s%.1024s",ExceptionSeverityToTag(severity),tag);
 
517
      locale_message=GetLocaleMessage(message);
 
518
      if (locale_message == message)
 
519
        return(tag);
 
520
      return(locale_message);
 
521
   }
 
522
  return(tag);
 
523
}
 
524
 
 
525
/*
 
526
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
527
%                                                                             %
 
528
%                                                                             %
 
529
%                                                                             %
 
530
%   M a g i c k E r r o r                                                     %
 
531
%                                                                             %
 
532
%                                                                             %
 
533
%                                                                             %
 
534
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
535
%
 
536
%  Method MagickError calls the error handler methods with an error reason.
 
537
%
 
538
%  The format of the MagickError method is:
 
539
%
 
540
%      void MagickError(const ExceptionType error,const char *reason,
 
541
%        const char *description)
 
542
%
 
543
%  A description of each parameter follows:
 
544
%
 
545
%    o exception: Specifies the numeric error category.
 
546
%
 
547
%    o reason: Specifies the reason to display before terminating the
 
548
%      program.
 
549
%
 
550
%    o description: Specifies any description to the reason.
 
551
%
 
552
%
 
553
*/
 
554
#if defined(MagickError)
 
555
MagickExport void _MagickError(const ExceptionType error,const char *reason,
 
556
  const char *description)
 
557
{
 
558
  if (error_handler != (ErrorHandler) NULL)
 
559
    (*error_handler)(error,GetLocaleExceptionMessage(error,reason),
 
560
      GetLocaleExceptionMessage(error,description));
 
561
}
 
562
#endif
 
563
#undef MagickError
 
564
MagickExport void MagickError(const ExceptionType error,const char *reason,
 
565
  const char *description)
 
566
{
 
567
  if (error_handler != (ErrorHandler) NULL)
 
568
    (*error_handler)(error,GetLocaleExceptionMessage(error,reason),
 
569
      GetLocaleExceptionMessage(error,description));
 
570
}
 
571
 
 
572
/*
 
573
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
574
%                                                                             %
 
575
%                                                                             %
 
576
%                                                                             %
 
577
%   M a g i c k F a t a l E r r o r                                           %
 
578
%                                                                             %
 
579
%                                                                             %
 
580
%                                                                             %
 
581
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
582
%
 
583
%  MagickFatalError() calls the fatal error handler methods with an error
 
584
%  reason.
 
585
%
 
586
%  The format of the MagickError method is:
 
587
%
 
588
%      void MagickFatalError(const ExceptionType error,const char *reason,
 
589
%        const char *description)
 
590
%
 
591
%  A description of each parameter follows:
 
592
%
 
593
%    o exception: Specifies the numeric error category.
 
594
%
 
595
%    o reason: Specifies the reason to display before terminating the
 
596
%      program.
 
597
%
 
598
%    o description: Specifies any description to the reason.
 
599
%
 
600
%
 
601
*/
 
602
#if defined(MagickFatalError)
 
603
MagickExport void _MagickFatalError(const ExceptionType error,const char *reason,
 
604
  const char *description)
 
605
{
 
606
  if (fatal_error_handler != (ErrorHandler) NULL)
 
607
    (*fatal_error_handler)(error,GetLocaleExceptionMessage(error,reason),
 
608
      GetLocaleExceptionMessage(error,description));
 
609
  errno=0;
 
610
}
 
611
#endif
 
612
#undef MagickFatalError
 
613
MagickExport void MagickFatalError(const ExceptionType error,const char *reason,
 
614
  const char *description)
 
615
{
 
616
  if (fatal_error_handler != (ErrorHandler) NULL)
 
617
    (*fatal_error_handler)(error,GetLocaleExceptionMessage(error,reason),
 
618
      GetLocaleExceptionMessage(error,description));
 
619
  errno=0;
 
620
}
 
621
 
 
622
/*
 
623
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
624
%                                                                             %
 
625
%                                                                             %
 
626
%                                                                             %
 
627
%   M a g i c k W a r n i n g                                                 %
 
628
%                                                                             %
 
629
%                                                                             %
 
630
%                                                                             %
 
631
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
632
%
 
633
%  Method MagickWarning calls the warning handler methods with a warning
 
634
%  reason.
 
635
%
 
636
%  The format of the MagickWarning method is:
 
637
%
 
638
%      void MagickWarning(const ExceptionType warning,const char *reason,
 
639
%        const char *description)
 
640
%
 
641
%  A description of each parameter follows:
 
642
%
 
643
%    o warning: The warning severity.
 
644
%
 
645
%    o reason: Define the reason for the warning.
 
646
%
 
647
%    o description: Describe the warning.
 
648
%
 
649
%
 
650
*/
 
651
#if defined(MagickWarning)
 
652
MagickExport void _MagickWarning(const ExceptionType warning,const char *reason,
 
653
  const char *description)
 
654
{
 
655
  if (warning_handler != (WarningHandler) NULL)
 
656
    (*warning_handler)(warning,GetLocaleExceptionMessage(warning,reason),
 
657
      GetLocaleExceptionMessage(warning,description));
 
658
}
 
659
#endif
 
660
#undef MagickWarning
 
661
MagickExport void MagickWarning(const ExceptionType warning,const char *reason,
 
662
  const char *description)
 
663
{
 
664
  if (warning_handler != (WarningHandler) NULL)
 
665
    (*warning_handler)(warning,GetLocaleExceptionMessage(warning,reason),
 
666
      GetLocaleExceptionMessage(warning,description));
 
667
}
 
668
 
 
669
/*
 
670
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
671
%                                                                             %
 
672
%                                                                             %
 
673
%                                                                             %
 
674
%   S e t E r r o r H a n d l e r                                             %
 
675
%                                                                             %
 
676
%                                                                             %
 
677
%                                                                             %
 
678
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
679
%
 
680
%  SetErrorHandler() sets the error handler to the specified method
 
681
%  and returns the previous error handler.
 
682
%
 
683
%  The format of the SetErrorHandler method is:
 
684
%
 
685
%      ErrorHandler SetErrorHandler(ErrorHandler handler)
 
686
%
 
687
%  A description of each parameter follows:
 
688
%
 
689
%    o handler: The method to handle errors.
 
690
%
 
691
%
 
692
*/
 
693
MagickExport ErrorHandler SetErrorHandler(ErrorHandler handler)
 
694
{
 
695
  ErrorHandler
 
696
    previous_handler;
 
697
 
 
698
  previous_handler=error_handler;
 
699
  error_handler=handler;
 
700
  return(previous_handler);
 
701
}
 
702
 
 
703
/*
 
704
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
705
%                                                                             %
 
706
%                                                                             %
 
707
%                                                                             %
 
708
%   S e t E x c e p t i o n I n f o                                           %
 
709
%                                                                             %
 
710
%                                                                             %
 
711
%                                                                             %
 
712
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
713
%
 
714
%  SetExceptionInfo() set the exception severity.
 
715
%
 
716
%  The format of the SetExceptionInfo method is:
 
717
%
 
718
%      SetExceptionInfo(ExceptionInfo *exception,ExceptionType severity)
 
719
%
 
720
%  A description of each parameter follows:
 
721
%
 
722
%    o exception: The exception info.
 
723
%
 
724
%    o severity: The exception severity.
 
725
%
 
726
%
 
727
*/
 
728
MagickExport void SetExceptionInfo(ExceptionInfo *exception,
 
729
  ExceptionType severity)
 
730
{
 
731
  assert(exception != (ExceptionInfo *) NULL);
 
732
  exception->severity=severity;
 
733
  errno=0;
 
734
}
 
735
 
 
736
/*
 
737
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
738
%                                                                             %
 
739
%                                                                             %
 
740
%                                                                             %
 
741
%   S e t F a t a l E r r o r H a n d l e r                                   %
 
742
%                                                                             %
 
743
%                                                                             %
 
744
%                                                                             %
 
745
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
746
%
 
747
%  SetFatalErrorHandler() sets the fatal error handler to the specified method
 
748
%  and returns the previous fatal error handler.
 
749
%
 
750
%  The format of the SetErrorHandler method is:
 
751
%
 
752
%      ErrorHandler SetErrorHandler(ErrorHandler handler)
 
753
%
 
754
%  A description of each parameter follows:
 
755
%
 
756
%    o handler: The method to handle errors.
 
757
%
 
758
%
 
759
*/
 
760
MagickExport FatalErrorHandler SetFatalErrorHandler(FatalErrorHandler handler)
 
761
{
 
762
  FatalErrorHandler
 
763
    previous_handler;
 
764
 
 
765
  previous_handler=fatal_error_handler;
 
766
  fatal_error_handler=handler;
 
767
  return(previous_handler);
 
768
}
 
769
 
 
770
/*
 
771
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
772
%                                                                             %
 
773
%                                                                             %
 
774
%                                                                             %
 
775
%   S e t W a r n i n g H a n d l e r                                         %
 
776
%                                                                             %
 
777
%                                                                             %
 
778
%                                                                             %
 
779
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
780
%
 
781
%  SetWarningHandler() sets the warning handler to the specified method
 
782
%  and returns the previous warning handler.
 
783
%
 
784
%  The format of the SetWarningHandler method is:
 
785
%
 
786
%      ErrorHandler SetWarningHandler(ErrorHandler handler)
 
787
%
 
788
%  A description of each parameter follows:
 
789
%
 
790
%    o handler: The method to handle warnings.
 
791
%
 
792
%
 
793
*/
 
794
MagickExport WarningHandler SetWarningHandler(WarningHandler handler)
 
795
{
 
796
  WarningHandler
 
797
    previous_handler;
 
798
 
 
799
  previous_handler=warning_handler;
 
800
  warning_handler=handler;
 
801
  return(previous_handler);
 
802
}
 
803
 
 
804
/*
 
805
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
806
%                                                                             %
 
807
%                                                                             %
 
808
%                                                                             %
 
809
%   T h r o w E x c e p t i o n                                               %
 
810
%                                                                             %
 
811
%                                                                             %
 
812
%                                                                             %
 
813
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
814
%
 
815
%  ThrowException() throws an exception with the specified severity code,
 
816
%  reason, and optional description.
 
817
%
 
818
%  The format of the ThrowException method is:
 
819
%
 
820
%      void ThrowException(ExceptionInfo *exception,
 
821
%        const ExceptionType severity,const char *reason,
 
822
%        const char *description)
 
823
%
 
824
%  A description of each parameter follows:
 
825
%
 
826
%    o exception: The exception.
 
827
%
 
828
%    o severity: The severity of the exception.
 
829
%
 
830
%    o reason: The reason of the exception.
 
831
%
 
832
%    o description: The exception description.
 
833
%
 
834
%
 
835
*/
 
836
#undef ThrowException
 
837
MagickExport void ThrowException(ExceptionInfo *exception,
 
838
  const ExceptionType severity,const char *reason,const char *description)
 
839
{
 
840
  assert(exception != (ExceptionInfo *) NULL);
 
841
  assert(exception->signature == MagickSignature);
 
842
  exception->severity=(ExceptionType) severity;
 
843
  MagickFreeMemory(exception->reason);
 
844
  if (reason)
 
845
    exception->reason=
 
846
      AcquireString(GetLocaleExceptionMessage(severity,reason));
 
847
  MagickFreeMemory(exception->description);
 
848
  if (description)
 
849
    exception->description=
 
850
      AcquireString(GetLocaleExceptionMessage(severity,description));
 
851
  exception->error_number=errno;
 
852
  MagickFreeMemory(exception->module);
 
853
  MagickFreeMemory(exception->function);
 
854
  exception->line=0UL;
 
855
  exception->signature=0UL;
 
856
  return;
 
857
}
 
858
 
 
859
/*
 
860
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
861
%                                                                             %
 
862
%                                                                             %
 
863
%                                                                             %
 
864
%   T h r o w L o g g e d E x c e p t i o n                                   %
 
865
%                                                                             %
 
866
%                                                                             %
 
867
%                                                                             %
 
868
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
869
%
 
870
%  ThrowLoggedException() throws an exception with the specified severity code,
 
871
%  reason, optional description, source filename, function name, and line
 
872
%  number. If logging is enabled, the exception is also logged.
 
873
%
 
874
%  The format of the ThrowLoggedException method is:
 
875
%
 
876
%      void ThrowLoggedException(ExceptionInfo *exception,
 
877
%        const ExceptionType severity,const char *reason,
 
878
%        const char *description,const char *module,
 
879
%        const char *function,const unsigned long line
 
880
%
 
881
%  A description of each parameter follows:
 
882
%
 
883
%    o exception: The exception.
 
884
%
 
885
%    o severity: The severity of the exception.
 
886
%
 
887
%    o reason: The reason of the exception.
 
888
%
 
889
%    o description: The exception description.
 
890
%
 
891
%    o filename: The source module filename.
 
892
%
 
893
%    o function: The function name.
 
894
%
 
895
%    o line: The line number of the source module.
 
896
%
 
897
%
 
898
*/
 
899
MagickExport void ThrowLoggedException(ExceptionInfo *exception,
 
900
  const ExceptionType severity,const char *reason,const char *description,
 
901
  const char *module,const char *function,const unsigned long line)
 
902
{
 
903
  assert(exception != (ExceptionInfo *) NULL);
 
904
  assert(exception->signature == MagickSignature);
 
905
  exception->severity=(ExceptionType) severity;
 
906
  MagickFreeMemory(exception->reason);
 
907
  if (reason)
 
908
    exception->reason=
 
909
      AcquireString(GetLocaleExceptionMessage(severity,reason));
 
910
  MagickFreeMemory(exception->description);
 
911
  if (description)
 
912
    exception->description=
 
913
      AcquireString(GetLocaleExceptionMessage(severity,description));
 
914
  exception->error_number=errno;
 
915
  MagickFreeMemory(exception->module);
 
916
  if (module)
 
917
    exception->module=AcquireString(module);
 
918
  MagickFreeMemory(exception->function);
 
919
  if (function)
 
920
    exception->function=AcquireString(function);
 
921
  exception->line=line;
 
922
  if (exception->reason)
 
923
    {
 
924
      if (exception->description)
 
925
        LogMagickEvent(severity,module,function,line,"%.1024s (%.1024s)",
 
926
          exception->reason,exception->description );
 
927
      else
 
928
        LogMagickEvent(severity,module,function,line,"%.1024s",
 
929
          exception->reason);
 
930
    }
 
931
  else
 
932
    {
 
933
      LogMagickEvent(severity,module,function,line,
 
934
        "exception contains no reason!");
 
935
    }
 
936
  return;
 
937
}