31.01.2014 Views

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

4.11 Error Handling ( error )<br />

<strong>LEDA</strong> tests the preconditions of many (not all!) operations. Preconditions are never<br />

tested, if the test takes more than constant time. If the test of a precondition fails an<br />

error handling routine is called. It takes an integer error number i and a char∗ error<br />

message string s as arguments. <strong>The</strong> default error handler writes s to the diagnostic<br />

output (cerr) and terminates the program abnormally if i ≠ 0. <strong>User</strong>s can provide their<br />

own error handling function handler by calling<br />

set_error_handler(handler)<br />

After this function call handler is used instead of the default error handler. handler<br />

must be a function of type void handler(int, const char∗). <strong>The</strong> parameters are replaced<br />

by the error number and the error message respectively.<br />

New:<br />

Starting with version 4.3 <strong>LEDA</strong> provides an exception error handler<br />

void exception error handler(int num, const char ∗ msg)<br />

This handler uses the C++exception mechanism and throws an exception of type<br />

leda exception instead of terminating the program. An object of type leda exception stores<br />

a pair consisting of an error number and an error message. Operations e.get msg( ) and<br />

e.get num( ) can be called to retrieve the corresponding values from an exception object<br />

e.<br />

1. Operations<br />

#include < <strong>LEDA</strong>/system/error.h ><br />

void<br />

error handler(int err no, const char ∗ msg)<br />

reports error messages by passing err no and msg<br />

to the default error handler.<br />

LedaErrorHandler set error handler(void (∗err handler)(int, const char∗))<br />

sets the default error handler to function<br />

err handler. Returns a pointer to the previous error<br />

handler.<br />

LedaErrorHandler get error handler( ) returns a pointer to the current default error handler.<br />

void<br />

catch system errors(bool b = true)<br />

after a call to this function system errors ( e.g.<br />

bus errors and segmentation faults) are handled<br />

by <strong>LEDA</strong>’s error handler.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!