COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/klao/error_test.cc @ 1120:5d8d64bde9c5

Last change on this file since 1120:5d8d64bde9c5 was 1120:5d8d64bde9c5, checked in by Mihaly Barasz, 19 years ago

Latest LEMON exception and assert concepts

File size: 1.3 KB
Line 
1#include <iostream>
2#include <string>
3
4#define LEMON_ASSERT_ABORT 0
5#include <error.h>
6
7using namespace std;
8
9void parse_line() {
10  throw lemon::DataFormatError("Syntax error");
11}
12
13void 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
24void fail_assert();
25
26int 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 <error.h>
73
74void fail_assert() {
75  LEMON_ASSERT(2*2==5, "Marson vagyunk");
76}
77
78
Note: See TracBrowser for help on using the repository browser.