Error Handlingtests the preconditions of many operations. If the test of a precondition fails, an error handling routine is called. Users can provide their own error handling function.Starting with version 4.3 LEDA provides an exception error handler
This handler uses the C++ exception mechanism and throws an exception of type leda_exception instead of terminating the program. An object of type Remark: The first error handling mechanism is historical. Since most compilers do support exceptions now, you better use the exception error handler. ExampleThe following program shows how to use the exception error handler. The
constructor #include <LEDA/geo/circle.h> int main() { // enable exceptions leda::set_error_handler(leda::exception_error_handler); leda::point p1(0,0);leda::point p2(1,1);leda::point p3(2,2); leda::circle C(p1,p2,p3); leda::point p; try {p = C.center();} catch(leda::leda_exception e) { std::cout << std::endl << "An exception occured: " << e.get_msg() << std::endl << std::endl; C = leda::circle(leda::point(0,0), leda::point(1,1), leda::point(1,0)); p = C.center(); } std::cout << "center of circle: " << p << std::endl; return 0; } |
See also: |