COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/klao/error2_test.cc @ 1224:7f4f2855fa11

Last change on this file since 1224:7f4f2855fa11 was 1157:3996d2098090, checked in by Mihaly Barasz, 20 years ago

lemon/error.h: boost::shared_ptr helyett std::auto_ptr

(Sokkal kenylemetlenebb, es nem teljesen biztos, hogy helyes megoldas)

File size: 896 bytes
Line 
1#include <iostream>
2#include <memory>
3
4#include <boost/shared_ptr.hpp>
5
6using namespace std;
7
8class Ex : public exception {
9
10  typedef exception Parent;
11
12  mutable
13  auto_ptr<string> uz;
14public:
15
16  // boost::shared_ptr<string> uz;
17
18  Ex(const Ex &e) : Parent(e), uz(e.uz) {}
19
20  explicit
21  Ex(const char *msg = 0) {
22    if( msg ) {
23      try {
24        uz.reset(new string);
25        *uz = msg;
26      }
27      catch(...) {
28        uz.reset();
29      }
30    }
31  }
32
33  virtual
34  const char* what() const throw() {
35    if( uz.get() )
36      return uz->c_str();
37    return "Kivetel";
38  }
39
40  virtual ~Ex() throw() {}
41};
42
43static void fn1() {
44  Ex e("alma");
45  throw e;
46}
47
48static
49void fn2() {
50  throw Ex("korte");
51}
52
53int main() {
54  try {
55    fn1();
56  }
57  catch(exception const &e) {
58    cerr << "Hiba: " << e.what() << endl;
59  }
60
61  try {
62    fn2();
63  }
64  catch(exception const &e) {
65    cerr << "Hiba: " << e.what() << endl;
66  }
67
68}
Note: See TracBrowser for help on using the repository browser.