Last change
on this file since 1099:91a8ee9d088d was
1067:47939f501c81,
checked in by Mihaly Barasz, 20 years ago
|
Advances in error.h
- More clear exception usage concept
- sketch of LEMON_ASSERT interface
- test file
|
File size:
903 bytes
|
Line | |
---|
1 | #include <iostream> |
---|
2 | #include <string> |
---|
3 | |
---|
4 | #define LEMON_ASSERT_ABORT 0 |
---|
5 | #include <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.set_file(fn); |
---|
19 | e.set_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(exception &e) { |
---|
31 | cerr << "Exception caught: " << endl; |
---|
32 | cerr << e.what() << endl; |
---|
33 | } |
---|
34 | |
---|
35 | try { |
---|
36 | fail_assert(); |
---|
37 | } |
---|
38 | catch(exception &e) { |
---|
39 | cerr << "Exception caught: " << endl; |
---|
40 | cerr << e.what() << endl; |
---|
41 | } |
---|
42 | |
---|
43 | // assert(1==0); |
---|
44 | LEMON_ASSERT(1==0, "Ellentmondas"); |
---|
45 | LEMON_FIXME("Nincs kesz"); |
---|
46 | } |
---|
47 | |
---|
48 | #undef LEMON_ASSERT_HANDLER |
---|
49 | #define LEMON_ASSERT_HANDLER ::lemon::assert_fail_throw |
---|
50 | |
---|
51 | #include <error.h> |
---|
52 | |
---|
53 | void fail_assert() { |
---|
54 | LEMON_ASSERT(2*2==5, "Marson vagyunk"); |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
Note: See
TracBrowser
for help on using the repository browser.