COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/klao/error_test.cc @ 1080:568ce2be7fe0

Last change on this file since 1080:568ce2be7fe0 was 1067:47939f501c81, checked in by Mihaly Barasz, 17 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
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.set_file(fn);
19    e.set_line(5);
20    throw;
21  }
22}
23
24void fail_assert();
25
26int 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
53void fail_assert() {
54  LEMON_ASSERT(2*2==5, "Marson vagyunk");
55}
56
57
Note: See TracBrowser for help on using the repository browser.