iError Project Site at SourceForge.net Logo
Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Usage

Before using of error handling define error codes.
For Example:
      iErrorCode OBJ_NOT_FOUND("Object %s not found", 13);
      iErrorCode WRONG_POS("Wrong Position (%d,%d)");
 
The first argument is the description of the error with %-tags indicating insertion points and type of context info. Use %-tags just like in printf. The string of the code description is not copied, so please use only constant strings or static char arrays. The second argument is optional and is the error code as an integer value (default is 0). It is more appropriate to declare iErrorCode objects as extern in header file and define them in the implementation file. There are also predefined error codes GENERIC, INTERNAL and SYSTEM.

To throw an error use iThrow macro. For Example:

 iThrow(CRITICAL(OBJ_NOT_FOUND), "myObj");
 
see iERR::iError::ErrorLevel for info about various error severities. Errors are thrown and handled by a iErrorHandler object. You may create your own error handler (see iErrorHanler) or you can use the default error handler (iStdErrorHandler). After an iThrow call an instance of iError is stored as last error (CRITICAL), thrown as C++ exception (EXCEPTION) or directly handled (WARNING). If the execution of a call not succeseeded, the caller may retrive the last occured error by calling iLastError() and display it, write it to a log file or simple ignore

The easiest way to handle an eror is to call iHandleError() macro to let the the current error handler handle the error. The default error handler will simple display a message with the error description and debug info.

If an error was thrown as C++ exception, it can be catched by catch(void*) and then handled or rethrown by using iRethrow macro. The iAssert macro can be used to display a message and exit if some assumed conditions are not fulfilled. It throws a special error code iERR_ASSERT with severity iASSERTION.

The Current error handler is managed on per thread basis. For the main thread the dafault error handler (iStdErrorHandler) is already created, but it is also used in other threads until you set an other error handler (iErrorHandler::SetCurrent).


© 2002 by C-LAB
generated by doxygen