DevIL Logo
      A full featured cross-platform image library.




SourceForge Home





Contact Us

Tutorial 3: DevIL Error HandlingLast Revised: 6:54 PM 11/26/2000
DevIL is designed to be as robust as possible, and your programs should be no different. DevIL provides an error-handling solution similar (but not exactly like) OpenGL's. When a detectable error occurs somewhere in DevIL, such as when the user passes a NULL parameter in a function that requires a valid pointer, DevIL sets the error in an internal error stack, which is at least 32 errors deep. If you get as high as 32 errors, you need to poll the error stack more often. ilGetError returns errors in the reverse order they occurred (last one returned first, like a regular stack). If an error occurs, DevIL is not immediately crippled but will continue to function, though it may not behave how you want it to if the errored function was supposed to set a state or something similar. To poll the error stack, call ilGetError with no parameters:

ILenum ilGetError (ILvoid);

If no detectable errors have occurred, ilGetError returns the IL_NO_ERROR message consistently. In the case of an error happening, ilGetError returns a value listed in the docs. If IL_OUT_OF_MEMORY occurs, pray that your application can at least exit correctly.

Code snippet that uses DevIL to retrieve errors

ILenum Error;
while ((Error = ilGetError()) != IL_NO_ERROR) {
    printf("%d: %s/n", Error, iluErrorString());

iluErrorString is a convenient function that produces a human-readable string of the current error. iluErrorString just requires one parameter:

const ILbyte *iluErrorString (ILenum Error);

Error is the value of the error that occurred. As an example, if IL_NO_ERROR is passed as Error, iluErrorString returns the const string "no error".