src/work/klao/error_test.cc
author alpar
Wed, 23 Feb 2005 10:53:17 +0000
changeset 1171 f426c84a4e00
parent 1120 5d8d64bde9c5
permissions -rw-r--r--
Experimental autopackage specfile.
     1 #include <iostream>
     2 #include <string>
     3 
     4 #define LEMON_ASSERT_ABORT 0
     5 #include <lemon/error.h>
     6 
     7 using namespace std;
     8 
     9 void parse_line() {
    10   throw lemon::DataFormatError("Syntax error");
    11 }
    12 
    13 void parse_file(string fn) {
    14   try {
    15     parse_line();
    16   }
    17   catch(lemon::DataFormatError &e) {
    18     e.file(fn);
    19     e.line(5);
    20     throw;
    21   }
    22 }
    23 
    24 void fail_assert();
    25 
    26 int main() {
    27   try {
    28     parse_file("input.txt");
    29   }
    30   catch(lemon::Exception &e) {
    31     cerr << "Exception '" << e.exceptionName()
    32 	 << "' caught: " << endl;
    33     cerr << e.what() << endl;
    34   }
    35   catch(exception &e) {
    36     cerr << "Exception caught: " << endl;
    37     cerr << e.what() << endl;
    38   }
    39 
    40   try {
    41     throw lemon::LogicError();
    42   }
    43   catch(lemon::Exception &e) {
    44     cerr << "Exception '" << e.exceptionName()
    45 	 << "' caught: " << endl;
    46     cerr << e.what() << endl;
    47   }
    48 
    49   try {
    50     fail_assert();
    51   }
    52   catch(lemon::Exception &e) {
    53     cerr << "Exception '" << e.exceptionName()
    54 	 << "' caught: " << endl;
    55     cerr << e.what() << endl;
    56   }
    57   catch(exception &e) {
    58     cerr << "Exception caught: " << endl;
    59     cerr << e.what() << endl;
    60   }
    61 
    62   cerr << endl;
    63 
    64   // assert(1==0);
    65   LEMON_ASSERT(1==0, "Ellentmondas");
    66   LEMON_FIXME("Nincs kesz");
    67 }
    68 
    69 #undef LEMON_ASSERT_HANDLER
    70 #define LEMON_ASSERT_EXCEPTION
    71 
    72 #include <lemon/error.h>
    73 
    74 void fail_assert() {
    75   LEMON_ASSERT(2*2==5, "Marson vagyunk");
    76 }