The C++ Template Image Processing Library. |

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

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

# CImgException Struct Reference

The CImgException class is used to throw general exceptions when an error occurs in a library call. More...

Inheritance diagram for CImgException:

List of all members.

## Public Attributes

char | message [1024]
| Error message.

## Detailed Description

The CImgException class is used to throw general exceptions when an error occurs in a library call.

The CImgException class is the base class of all CImg exceptions. Exceptions are thrown by the CImg Library when an error occurs during the execution of a CImg function. The CImgException is seldom thrown itself, children classes (that specify the type of error) are generally used instead. It may be thrown anyway for non-specialized exception types.

See also:
  CImgInstanceException, CImgArgumentException, CImgIOException and CImgDisplayException.

By default, when an error occurs, the CImg Library displays an error message on the standart error output stderr (on Unix), or opens a pop-up window displaying the error message (on Windows). Then, it throws an instance of an exception class, generally leading the program to stop (this is the default behavior of the C++ exception mechanism). You can always bypass this behavior by handling the exceptions by yourself (using a code block `try { ... } catch() { ... }`). Then, if you don't want the CImg Library to display error messages, you can define the environment variable `cimg_debug` to 0 before including the header file `CImg.h` (see Setting Environment Variables).

The `CImgException` class owns a member variable `char* message` that contains the exception message describing precisely the error that occured.

The example above shows how to manually handle CImg Library errors properly :

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

Definition at line 608 of file CImg.h.