1 /*
2   Copyright (C) 2003-2020 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   GraphicsMagick Exception Methods.
11 */
12 #ifndef _MAGICK_ERROR_H
13 #define _MAGICK_ERROR_H
14 
15 #if defined(__cplusplus) || defined(c_plusplus)
16 extern "C" {
17 #endif /* defined(__cplusplus) || defined(c_plusplus) */
18 
19 /*
20   Enum declarations.
21 */
22 typedef enum
23 {
24   UndefinedExceptionBase = 0,
25   ExceptionBase = 1,
26   ResourceBase = 2,
27   ResourceLimitBase = 2,
28   TypeBase = 5,
29   AnnotateBase = 5,
30   OptionBase = 10,
31   DelegateBase = 15,
32   MissingDelegateBase = 20,
33   CorruptImageBase = 25,
34   FileOpenBase = 30,
35   BlobBase = 35,
36   StreamBase = 40,
37   CacheBase = 45,
38   CoderBase = 50,
39   ModuleBase = 55,
40   DrawBase = 60,
41   RenderBase = 60,
42   ImageBase = 65,
43   WandBase = 67,
44   TemporaryFileBase = 70,
45   TransformBase = 75,
46   XServerBase = 80,
47   X11Base = 81,
48   UserBase = 82,
49   MonitorBase = 85,
50   LocaleBase = 86,
51   DeprecateBase = 87,
52   RegistryBase = 90,
53   ConfigureBase = 95
54 } ExceptionBaseType;
55 
56 typedef enum
57 {
58   UndefinedException = 0,
59   EventException = 100,
60   ExceptionEvent = EventException + ExceptionBase,
61   ResourceEvent = EventException + ResourceBase,
62   ResourceLimitEvent = EventException + ResourceLimitBase,
63   TypeEvent = EventException + TypeBase,
64   AnnotateEvent = EventException + AnnotateBase,
65   OptionEvent = EventException + OptionBase,
66   DelegateEvent = EventException + DelegateBase,
67   MissingDelegateEvent = EventException + MissingDelegateBase,
68   CorruptImageEvent = EventException + CorruptImageBase,
69   FileOpenEvent = EventException + FileOpenBase,
70   BlobEvent = EventException + BlobBase,
71   StreamEvent = EventException + StreamBase,
72   CacheEvent = EventException + CacheBase,
73   CoderEvent = EventException + CoderBase,
74   ModuleEvent = EventException + ModuleBase,
75   DrawEvent = EventException + DrawBase,
76   RenderEvent = EventException + RenderBase,
77   ImageEvent = EventException + ImageBase,
78   WandEvent = EventException + WandBase,
79   TemporaryFileEvent = EventException + TemporaryFileBase,
80   TransformEvent = EventException + TransformBase,
81   XServerEvent = EventException + XServerBase,
82   X11Event = EventException + X11Base,
83   UserEvent = EventException + UserBase,
84   MonitorEvent = EventException + MonitorBase,
85   LocaleEvent = EventException + LocaleBase,
86   DeprecateEvent = EventException + DeprecateBase,
87   RegistryEvent = EventException + RegistryBase,
88   ConfigureEvent = EventException + ConfigureBase,
89 
90   WarningException = 300,
91   ExceptionWarning = WarningException + ExceptionBase,
92   ResourceWarning = WarningException + ResourceBase,
93   ResourceLimitWarning = WarningException + ResourceLimitBase,
94   TypeWarning = WarningException + TypeBase,
95   AnnotateWarning = WarningException + AnnotateBase,
96   OptionWarning = WarningException + OptionBase,
97   DelegateWarning = WarningException + DelegateBase,
98   MissingDelegateWarning = WarningException + MissingDelegateBase,
99   CorruptImageWarning = WarningException + CorruptImageBase,
100   FileOpenWarning = WarningException + FileOpenBase,
101   BlobWarning = WarningException + BlobBase,
102   StreamWarning = WarningException + StreamBase,
103   CacheWarning = WarningException + CacheBase,
104   CoderWarning = WarningException + CoderBase,
105   ModuleWarning = WarningException + ModuleBase,
106   DrawWarning = WarningException + DrawBase,
107   RenderWarning = WarningException + RenderBase,
108   ImageWarning = WarningException + ImageBase,
109   WandWarning = WarningException + WandBase,
110   TemporaryFileWarning = WarningException + TemporaryFileBase,
111   TransformWarning = WarningException + TransformBase,
112   XServerWarning = WarningException + XServerBase,
113   X11Warning = WarningException + X11Base,
114   UserWarning = WarningException + UserBase,
115   MonitorWarning = WarningException + MonitorBase,
116   LocaleWarning = WarningException + LocaleBase,
117   DeprecateWarning = WarningException + DeprecateBase,
118   RegistryWarning = WarningException + RegistryBase,
119   ConfigureWarning = WarningException + ConfigureBase,
120 
121   ErrorException = 400,
122   ExceptionError = ErrorException + ExceptionBase,
123   ResourceError = ErrorException + ResourceBase,
124   ResourceLimitError = ErrorException + ResourceLimitBase,
125   TypeError = ErrorException + TypeBase,
126   AnnotateError = ErrorException + AnnotateBase,
127   OptionError = ErrorException + OptionBase,
128   DelegateError = ErrorException + DelegateBase,
129   MissingDelegateError = ErrorException + MissingDelegateBase,
130   CorruptImageError = ErrorException + CorruptImageBase,
131   FileOpenError = ErrorException + FileOpenBase,
132   BlobError = ErrorException + BlobBase,
133   StreamError = ErrorException + StreamBase,
134   CacheError = ErrorException + CacheBase,
135   CoderError = ErrorException + CoderBase,
136   ModuleError = ErrorException + ModuleBase,
137   DrawError = ErrorException + DrawBase,
138   RenderError = ErrorException + RenderBase,
139   ImageError = ErrorException + ImageBase,
140   WandError = ErrorException + WandBase,
141   TemporaryFileError = ErrorException + TemporaryFileBase,
142   TransformError = ErrorException + TransformBase,
143   XServerError = ErrorException + XServerBase,
144   X11Error = ErrorException + X11Base,
145   UserError = ErrorException + UserBase,
146   MonitorError = ErrorException + MonitorBase,
147   LocaleError = ErrorException + LocaleBase,
148   DeprecateError = ErrorException + DeprecateBase,
149   RegistryError = ErrorException + RegistryBase,
150   ConfigureError = ErrorException + ConfigureBase,
151 
152   FatalErrorException = 700,
153   ExceptionFatalError = FatalErrorException + ExceptionBase,
154   ResourceFatalError = FatalErrorException + ResourceBase,
155   ResourceLimitFatalError = FatalErrorException + ResourceLimitBase,
156   TypeFatalError = FatalErrorException + TypeBase,
157   AnnotateFatalError = FatalErrorException + AnnotateBase,
158   OptionFatalError = FatalErrorException + OptionBase,
159   DelegateFatalError = FatalErrorException + DelegateBase,
160   MissingDelegateFatalError = FatalErrorException + MissingDelegateBase,
161   CorruptImageFatalError = FatalErrorException + CorruptImageBase,
162   FileOpenFatalError = FatalErrorException + FileOpenBase,
163   BlobFatalError = FatalErrorException + BlobBase,
164   StreamFatalError = FatalErrorException + StreamBase,
165   CacheFatalError = FatalErrorException + CacheBase,
166   CoderFatalError = FatalErrorException + CoderBase,
167   ModuleFatalError = FatalErrorException + ModuleBase,
168   DrawFatalError = FatalErrorException + DrawBase,
169   RenderFatalError = FatalErrorException + RenderBase,
170   ImageFatalError = FatalErrorException + ImageBase,
171   WandFatalError = FatalErrorException + WandBase,
172   TemporaryFileFatalError = FatalErrorException + TemporaryFileBase,
173   TransformFatalError = FatalErrorException + TransformBase,
174   XServerFatalError = FatalErrorException + XServerBase,
175   X11FatalError = FatalErrorException + X11Base,
176   UserFatalError = FatalErrorException + UserBase,
177   MonitorFatalError = FatalErrorException + MonitorBase,
178   LocaleFatalError = FatalErrorException + LocaleBase,
179   DeprecateFatalError = FatalErrorException + DeprecateBase,
180   RegistryFatalError = FatalErrorException + RegistryBase,
181   ConfigureFatalError = FatalErrorException + ConfigureBase
182 } ExceptionType;
183 
184 /*
185   Typedef declarations.
186 */
187 
188 /*
189   ExceptionInfo is used to report exceptions to higher level routines,
190   and to the user.
191 */
192 typedef struct _ExceptionInfo
193 {
194   /*
195     Exception severity, reason, and description
196   */
197   ExceptionType
198     severity;
199 
200   char
201     *reason,
202     *description;
203 
204   /*
205     Value of errno (or equivalent) when exception was thrown.
206   */
207   int
208     error_number;
209 
210   /*
211     Reporting source module, function (if available), and source
212     module line.
213   */
214   char
215     *module,
216     *function;
217 
218   unsigned long
219     line;
220 
221   /*
222     Structure sanity check
223   */
224   unsigned long
225     signature;
226 } ExceptionInfo;
227 
228 /*
229   Exception typedef declarations.
230 */
231 typedef void
232   (*ErrorHandler)(const ExceptionType,const char *,const char *);
233 
234 typedef void
235   (*FatalErrorHandler)(const ExceptionType,const char *,const char *) MAGICK_FUNC_NORETURN;
236 
237 typedef void
238   (*WarningHandler)(const ExceptionType,const char *,const char *);
239 
240 /*
241   Exception declarations.
242 */
243 extern MagickExport const char
244   *GetLocaleExceptionMessage(const ExceptionType,const char *),
245   *GetLocaleMessage(const char *);
246 
247 extern MagickExport ErrorHandler
248   SetErrorHandler(ErrorHandler);
249 
250 extern MagickExport FatalErrorHandler
251   SetFatalErrorHandler(FatalErrorHandler);
252 
253 extern MagickExport void
254   CatchException(const ExceptionInfo *),
255   CopyException(ExceptionInfo *copy, const ExceptionInfo *original),
256   DestroyExceptionInfo(ExceptionInfo *),
257   GetExceptionInfo(ExceptionInfo *),
258   MagickError(const ExceptionType,const char *,const char *),
259   MagickFatalError(const ExceptionType,const char *,const char *) MAGICK_FUNC_NORETURN,
260   MagickWarning(const ExceptionType,const char *,const char *),
261   _MagickError(const ExceptionType,const char *,const char *),
262   _MagickFatalError(const ExceptionType,const char *,const char *) MAGICK_FUNC_NORETURN,
263   _MagickWarning(const ExceptionType,const char *,const char *),
264   SetExceptionInfo(ExceptionInfo *,ExceptionType),
265   ThrowException(ExceptionInfo *,const ExceptionType,const char *,const char *),
266   ThrowLoggedException(ExceptionInfo *exception, const ExceptionType severity,
267     const char *reason,const char *description,const char *module,
268     const char *function,const unsigned long line);
269 
270 extern MagickExport WarningHandler
271   SetWarningHandler(WarningHandler);
272 
273 /*
274   Exception define definitions.
275 */
276 
277 #include <magick/log.h>
278 
279 #if defined(MAGICK_IMPLEMENTATION)
280 
281 #  include "magick/error-private.h"
282 
283 #endif /* defined(MAGICK_IMPLEMENTATION) */
284 
285 #if defined(__cplusplus) || defined(c_plusplus)
286 }
287 #endif /* defined(__cplusplus) || defined(c_plusplus) */
288 
289 #endif /* !defined(_MAGICK_ERROR_H) */
290 
291 /*
292  * Local Variables:
293  * mode: c
294  * c-basic-offset: 2
295  * fill-column: 78
296  * End:
297  */
298