Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CImgException Struct Reference

Instances of this class are thrown when errors occur during a CImg library function call. More...

#include <CImg.h>

Inheritance diagram for CImgException:

Public Member Functions

 CImgException ()
 
 CImgException (const char *format,...)
 

Public Attributes

char message [16384]
 Message associated with the error that thrown the exception. More...
 

Detailed Description

Instances of this class are thrown when errors occur during a CImg library function call.

Overview

CImgException is the base class of CImg exceptions. Exceptions are thrown by the CImg Library when an error occured in a CImg library function call. CImgException is seldom thrown itself. Children classes that specify the kind of error encountered are generally used instead. These sub-classes are :

  • CImgInstanceException : Thrown when the instance associated to the called CImg function is not correctly defined. Generally, this exception is thrown when one tries to process empty images. The example below will throw a CImgInstanceException.
    CImg<float> img; // Construct an empty image.
    img.blur(10); // Try to blur the image.
  • CImgArgumentException : Thrown when one of the arguments given to the called CImg function is not correct. Generally, this exception is thrown when arguments passed to the function are outside an admissible range of values. The example below will throw a CImgArgumentException.
    CImg<float> img(100,100,1,3); // Define a 100x100 color image with float pixels.
    img = 0; // Try to fill pixels from the 0 pointer (invalid argument to operator=() ).
  • CImgIOException : Thrown when an error occured when trying to load or save image files. The example below will throw a CImgIOException.
    CImg<float> img("file_doesnt_exist.jpg"); // Try to load a file that doesn't exist.
  • CImgDisplayException : Thrown when an error occured when trying to display an image in a window. This exception is thrown when image display request cannot be satisfied.

The parent class CImgException may be thrown itself when errors that cannot be classified in one of the above type occur. It is recommended not to throw CImgExceptions yourself, since there are normally reserved to CImg Library functions. CImgInstanceException, CImgArgumentException, CImgIOException and CImgDisplayException are simple subclasses of CImgException and are thus not detailled more in this reference documentation.

Exception handling

When an error occurs, the CImg Library first displays the error in a modal window. Then, it throws an instance of the corresponding exception class, generally leading the program to stop (this is the default behavior). You can bypass this default behavior by handling the exceptions yourself, using a code block try { ... } catch() { ... }. In this case, you can avoid the apparition of the modal window, by defining the environment variable cimg_debug to 0 before including the CImg header file. The example below shows how to cleanly handle CImg Library exceptions :

#define cimg_debug 0 // Disable modal window in CImg exceptions.
#define "CImg.h"
int main() {
try {
...; // Here, do what you want.
}
catch (CImgInstanceException &e) {
std::fprintf(stderr,"CImg Library Error : %s",e.message); // Display your own error message
... // Do what you want now.
}
}

Definition at line 2020 of file CImg.h.

Constructor & Destructor Documentation

CImgException ( )
inline

Definition at line 2033 of file CImg.h.

References CImgException::message.

2033 { message[0] = 0; }
char message[16384]
Message associated with the error that thrown the exception.
Definition: CImg.h:2032
CImgException ( const char *  format,
  ... 
)
inline

Definition at line 2034 of file CImg.h.

References _cimg_exception_err.

2034 { _cimg_exception_err("CImgException",true); }
#define _cimg_exception_err(etype, disp_flag)
Definition: CImg.h:2021

Member Data Documentation

char message[16384]

Message associated with the error that thrown the exception.

Definition at line 2032 of file CImg.h.

Referenced by CImgException::CImgException(), CImg< uintT >::load(), and CImgList< uintT >::load().


The documentation for this struct was generated from the following file: