6459045
6459045
6459045
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
6459045
<head>
6459045
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6459045
<title>Magick++ API: Exceptions </title>
6459045
<link rel="stylesheet" href="magick.css" type="text/css" />
6459045
</head>
6459045
<body>
6459045
6459045

Magick::Exception Classes

6459045

Exception represents the base class of objects thrown when

6459045
Magick++reports an error. Magick++ throws C++ exceptions synchronous
6459045
with the operation where the error occurred. This allows errors to be
6459045
trapped within the enclosing code (perhaps the code to process a
6459045
single image) while allowing the code to be written with a simple
6459045
coding style.

6459045

A try/catch block should be placed around any sequence of

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

6459045

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

6459045

6459045
6459045
using namespace std;
6459045
for infile in list
6459045
{
6459045
  try {
6459045
    // Construct an image instance first so that we don't have to worry
6459045
    // about object construction failure due to a minor warning exception
6459045
    // being thrown.
6459045
    Magick::Image image; 
6459045
    try {
6459045
      // Try reading image file
6459045
      image.read(infile);
6459045
    }
6459045
    catch( Magick::WarningCoder &warning )
6459045
    {
6459045
      // Process coder warning while loading file (e.g. TIFF warning)
6459045
      // Maybe the user will be interested in these warnings (or not).
6459045
      // If a warning is produced while loading an image, the image
6459045
      // can normally still be used (but not if the warning was about
6459045
      // something important!)
6459045
      cerr << "Coder Warning: " << warning.what() << endl;
6459045
    }
6459045
    catch( Magick::Warning &warning )
6459045
    {
6459045
      // Handle any other Magick++ warning.
6459045
      cerr << "Warning: " << warning.what() << endl;
6459045
    }
6459045
    catch( Magick::ErrorFileOpen &error ) 
6459045
    { 
6459045
      // Process Magick++ file open error
6459045
      cerr << "Error: " << error.what() << endl;
6459045
      continue; // Try next image.
6459045
    }
6459045
    try {
6459045
      image.rotate(90);
6459045
      image.write("outfile");
6459045
    }
6459045
    catch ( MagickExeption & error)
6459045
    {
6459045
       // Handle problem while rotating or writing outfile.
6459045
       cerr << "Caught Magick++ exception: " << error.what() << endl;
6459045
    }
6459045
  }
6459045
  catch( std::exception & error ) 
6459045
  { 
6459045
     // Process any other exceptions derived from standard C++ exception
6459045
     cerr << "Caught C++ STD exception: " << error.what() << endl;
6459045
  } 
6459045
  catch( ... ) 
6459045
  { 
6459045
    // Process *any* exception (last-ditch effort). There is not a lot
6459045
    // you can do here other to retry the operation that failed, or exit
6459045
  }
6459045
}
6459045
6459045

The desired location and number of try/catch blocks in your program

6459045
depends how sophisticated its error handling must be. Very simple
6459045
programs may use just one try/catch block.

6459045

The Exception class is derived from the C++ standard

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

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

The classes Warning and Error derive from the

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

6459045

The specific derived exception classes

6459045
are shown in the following tables: 
6459045

6459045

Warning Sub-Classes

6459045
6459045
	
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">Warning</font>

6459045
		
6459045
		
6459045
			

<font size="2">Warning Description</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">WarningUndefined</font>

6459045
		
6459045
		
6459045
			

<font size="2">Unspecified warning type.</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">WarningBlob</font>

6459045
		
6459045
		
6459045
			

<font size="2">NOT

6459045
			CURRENTLY USED</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">WarningCache</font>

6459045
		
6459045
		
6459045
			

<font size="2">NOT

6459045
			CURRENTLY USED</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">WarningCoder</font>

6459045
		
6459045
		
6459045
			

<font size="2">Warnings issued by some coders.</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">WarningConfigure</font>

6459045
		
6459045
		
6459045
			

<font size="2">NOT

6459045
			CURRENTLY USED</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">WarningCorruptImage</font>

6459045
		
6459045
		
6459045
			

<font size="2">Warning issued when an image is determined to be

6459045
			corrupt.</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">WarningDelegate</font>

6459045
		
6459045
		
6459045
			

<font size="2">Warnings reported by the delegate (interface to

6459045
			external programs) subsystem.</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">WarningDraw</font>

6459045
		
6459045
		
6459045
			

<font size="2">Warnings reported by the rendering subsystem.</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">WarningFileOpen</font>

6459045
		
6459045
		
6459045
			

<font size="2">Warning reported when The image file could not be

6459045
			opened (permission problem, wrong file type, or does not exist).</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">WarningImage</font>

6459045
		
6459045
		
6459045
			

<font size="2">NOT CURRENTLY USED</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">WarningMissingDelegate</font>

6459045
		
6459045
		
6459045
			

<font size="2">NOT CURRENTLY USED</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">WarningModule</font>

6459045
		
6459045
		
6459045
			

<font size="2">NOT CURRENTLY USED</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">WarningMonitor</font>

6459045
		
6459045
		
6459045
			

<font size="2">NOT CURRENTLY USED</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">WarningOption</font>

6459045
		
6459045
		
6459045
			

<font size="2">Warning reported when an option is malformed or

6459045
			out of range.</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">WarningRegistry</font>

6459045
		
6459045
		
6459045
			

<font size="2">NOT CURRENTLY USED</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">WarningResourceLimit</font>

6459045
		
6459045
		
6459045
			

<font size="2">Warning reported when a program resource is

6459045
			exhausted (e.g. not enough memory).</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">WarningStream</font>

6459045
		
6459045
		
6459045
			

<font size="2">NOT CURRENTLY USED</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">WarningType</font>

6459045
		
6459045
		
6459045
			

<font size="2">NOT CURRENTLY USED</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">WarningXServer</font>

6459045
		
6459045
		
6459045
			

<font size="2">Warnings reported by the X11 subsystem.</font>

6459045
		
6459045
	
6459045
6459045


6459045

6459045

Error Sub-Classes

6459045
6459045
	
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">Error</font>

6459045
		
6459045
		
6459045
			

<font size="2">Error Description</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">ErrorUndefined</font>

6459045
		
6459045
		
6459045
			

<font size="2">Unspecified error type.</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">ErrorBlob</font>

6459045
		
6459045
		
6459045
			

<font size="2">Error reported by BLOB I/O subsystem.</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">ErrorCache</font>

6459045
		
6459045
		
6459045
			

<font size="2">Error reported by the pixel cache subsystem.</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">ErrorCoder</font>

6459045
		
6459045
		
6459045
			

<font size="2">Error reported by coders (image format support).</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">ErrorConfigure</font>

6459045
		
6459045
		
6459045
			

<font size="2">Errors reported while loading configuration files.</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">ErrorCorruptImage</font>

6459045
		
6459045
		
6459045
			

<font size="2">Error reported when the image file is corrupt.</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">ErrorDelegate</font>

6459045
		
6459045
		
6459045
			

<font size="2">Errors reported by the delegate (interface to

6459045
			external programs) subsystem.</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">ErrorDraw</font>

6459045
		
6459045
		
6459045
			

<font size="2">Error reported while drawing on image.</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">ErrorFileOpen</font>

6459045
		
6459045
		
6459045
			

<font size="2">Error reported when the image file can not be

6459045
			opened.</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">ErrorImage</font>

6459045
		
6459045
		
6459045
			

<font size="2">Errors reported while drawing.</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">ErrorMissingDelegate</font>

6459045
		
6459045
		
6459045
			

<font size="2">Error reported when an add-on library or program

6459045
			is necessary in order to support the requested operation.</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">ErrorModule</font>

6459045
		
6459045
		
6459045
			

<font size="2">Errors reported by the module loader subsystem.</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">ErrorMonitor</font>

6459045
		
6459045
		
6459045
			

<font size="2">NOT CURRENTLY USED</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">ErrorOption</font>

6459045
		
6459045
		
6459045
			

<font size="2">Error reported when an option is malformed or out

6459045
			of range.</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">ErrorRegistry</font>

6459045
		
6459045
		
6459045
			

<font size="2">Errors reported by the image/BLOB registry

6459045
			subsystem.</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">ErrorResourceLimit</font>

6459045
		
6459045
		
6459045
			

<font size="2">Error reported when a program resource is

6459045
			exhausted (e.g. not enough memory).</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">ErrorStream</font>

6459045
		
6459045
		
6459045
			

<font size="2">Errors reported by the pixel stream subsystem.</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">ErrorType</font>

6459045
		
6459045
		
6459045
			

<font size="2">Errors reported by the type (font) rendering

6459045
			subsystem.</font>

6459045
		
6459045
	
6459045
	
6459045
		
6459045
			

<font size="2">ErrorXServer</font>

6459045
		
6459045
		
6459045
			

<font size="2">Errors reported by the X11 subsystem.</font>

6459045
		
6459045
	
6459045
6459045



6459045

6459045
6459045
</body>
6459045
</html>