The C++ Template Image Processing Library.
Initially developped in the Odyssée Lab, at the INRIA-Sophia Antipolis.

[Introduction]- [Latest News]- [Download]- [Screenshots]- [Tutorial]- [Forums]- [Library Reference]- [SourceForge Repository ]

Main Page | Modules | Namespace List | Class Hierarchy | Class List | Namespace Members | Class Members

Using Exceptions.

Exception classes.

The CImg Library uses the mechanism of C++ exceptions to handle error control. We will not discuss the concept of exceptions here, but rather describe the CImg exceptions structure which is actually quite classical.

Basically, there is one base class CImgException and four subclasses that may be throwed by CImg library functions. These classes are described below :

Handling exceptions

By default, when an error occurs, the CImg Library will display an error message on the standart error output (Unix), or will open an error window containing the error message (Windows), then will throw the exception, leading the program to halt. If you want to bypass this behavior by handling the exceptions yourself, you have to define a code block try { ... } catch() { ... } and define the environment variable cimg_debug to 0, avoiding then the display of CImg exception messages.

The CImgException class owns a member variable char* message which contains the exception message corresponding to the precise description of the error that has been encountered. The way you can handle exception errors in your own code is then easy. The use of a code like this allows to handle CImg exceptions :

#define cimg_debug 0   // Disable error message display by CImg.
#define "CImg.h"
int main() {
 try {
    ...   // Here, do what you want.
 }
 catch (CImgException &e) {
    fprintf(stderr,"CImg Library Error : %s",e.message);   // Display error message
    ...            // Do what you want to save the ship !
 }
}



Generated on Tue Aug 10 17:35:47 2004 for The CImg Library by doxygen 1.3.8