next up previous contents index
Next: Files and Directories ( Up: Simple Data Types and Previous: Memory Allocator ( leda_allocator   Contents   Index


Error Handling ( error )

LEDA tests the preconditions of many (not all!) operations. Preconditions are never tested, if the test takes more than constant time. If the test of a precondition fails an error handling routine is called. It takes an integer error number i and a char* error message string s as arguments. The default error handler writes s to the diagnostic output (cerr) and terminates the program abnormally if i! = 0 . Users can provide their own error handling function handler by calling

 set_error_handler(handler)
After this function call handler is used instead of the default error handler. handler must be a function of type void handler(int, const char*). The parameters are replaced by the error number and the error message respectively.

New:
Starting with version 4.3 LEDA provides an exception error handler
void exception_error_handler(int num, const char* msg)
This handler uses the C++exception mechanism and throws an exception of type leda_exception instead of terminating the program. An object of type leda_exception stores a pair consisting of an error number and an error message. Operations e.get_msg() and e.get_num() can be called to retrieve the corresponding values from an exception object e .

Operations

#include < LEDA/system/error.h >

void error_handler(int err_no, const char* msg)
    reports error messages by passing err_no and msg to the default error handler.

LedaErrorHandler set_error_handler(void (*err_handler)(int, const char*))
    sets the default error handler to function err_handler. Returns a pointer to the previous error handler.

LedaErrorHandler get_error_handler() returns a pointer to the current default error handler.

void catch_system_errors(bool b=true)
    after a call to this function system errors ( e.g. bus errors and segmentation faults) are handled by LEDA's error handler.

bool leda_assert(bool cond, const char* err_msg, int err_no=0)
    calls error_handler(err_no,err_msg) if cond = false and returns cond.


next up previous contents index
Next: Files and Directories ( Up: Simple Data Types and Previous: Memory Allocator ( leda_allocator   Contents   Index
Christian Uhrig 2017-04-07