File: Exception.tex

package info (click to toggle)
imagemagick 6:6.0.6.2-2.9
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 33,284 kB
  • ctags: 14,844
  • sloc: ansic: 190,790; cpp: 17,203; sh: 8,740; perl: 4,190; makefile: 1,740; tcl: 459
file content (139 lines) | stat: -rw-r--r-- 4,511 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
\section{Magick::Exception Classes}
\scriptsize{
\begin{verbatim}

Exception represents the base class of objects thrown when ImageMagick
reports an error.  Magick++ throws C++ exceptions synchronous with the
operation when an error is detected. This allows errors to be trapped within
the enclosing code (perhaps the code to process a single image)  while
allowing the code to be written simply.

A try/catch block should be placed around any sequence of operations which
can be considered a unit of work. For example, if your program processes
lists of images and some of these images may be defective, by placing the
try/catch block around the entire sequence of code that processes one image
(including instantiating the image object), you can minimize the overhead of
error checking while ensuring that all objects created to deal with that
object are safely destroyed (C++ exceptions unroll the stack until the
enclosing try block, destroying any created objects).

The pseudocode for the main loop of your program may look like:

for each image in list
  try {
    create image object
    read image
    process image
    save result
  }
  catch( ErrorFileOpen &error )
  {
    process Magick++ file open error
  }
  catch( Exception &error )
  {
    process any Magick++ error
  }
  catch( exception &error )
  {
    process any other exceptions derived from standard C++ exception
  }
  catch( ... )
  {
    process *any* exception (last-ditch effort)
  }

This catches errors opening a file first, followed by any Magick++ exception
if the exception was not caught previously.

The Exception class is derived from the C++ standard exception class. This
means that it contains a C++ string containing additional information about
the error (e.g to display to the user). Obtain access to this string via the
what() method.  For example:

 catch( Exception &error_ )
    {
      cout << "Caught exception: " << error_.what() << endl;
    }

The classes Warning and Error derive from the Exception class. Exceptions
derived from Warning are thrown to represent non-fatal errors which may
effect the completeness or quality of the result (e.g. one image provided as
an argument to montage is defective). In most cases, a Warning exception may
be ignored by catching it immediately, processing it (e.g. printing a
diagnostic) and continuing on. Exceptions derived from Error are thrown to
represent fatal errors that can not produce a valid result (e.g. attempting
to read a file which does not exist).

The specific derived exception classes are shown in the following tables:

                             Warning Sub-Classes

 Warning                Warning Description

 WarningUndefined       Unspecified warning type.


 WarningResourceLimit   A program resource is exhausted (e.g. not enough
                        memory).

 WarningXServer         An X resource is unavailable.

 WarningOption          An option was malformed or out of range.

 WarningDelegate        An ImageMagick delegate returned an error.


 WarningMissingDelegate The image type can not be read or written because
                        the appropriate Delegate is missing.


 WarningCorruptImage    The image file is corrupt (or otherwise can't be
                        read).


 WarningFileOpen        The image file could not be opened (permission
                        problem, wrong file type, or does not exist).

 WarningBlob            A binary large object could not be allocated.

 WarningCache           Pixels could not be saved to the pixel cache.



                              Error Sub-Classes

 Error                Error Description

 ErrorUndefined       Unspecified error type.


 ErrorResourceLimit   A program resource is exhausted (e.g. not enough
                      memory).

 ErrorXServer         An X resource is unavailable.

 ErrorOption          An option was malformed or out of range.

 ErrorDelegate        An ImageMagick delegate returned an error.


 ErrorMissingDelegate The image type can not be read or written because the
                      appropriate Delegate is missing.


 ErrorCorruptImage    The image file is corrupt (or otherwise can't be
                      read).


 ErrorFileOpen        The image file could not be opened (permission
                      problem, wrong file type, or does not exist).

 ErrorBlob            A binary large object could not be allocated.

 ErrorCache           Pixels could not be saved to the pixel cache.



\end{verbatim}
}