author | alpar |
Wed, 23 Feb 2005 10:53:17 +0000 | |
changeset 1171 | f426c84a4e00 |
permissions | -rw-r--r-- |
1 #include <iostream>
2 #include <memory>
4 #include <boost/shared_ptr.hpp>
6 using namespace std;
8 class Ex : public exception {
10 typedef exception Parent;
12 mutable
13 auto_ptr<string> uz;
14 public:
16 // boost::shared_ptr<string> uz;
18 Ex(const Ex &e) : Parent(e), uz(e.uz) {}
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 }
33 virtual
34 const char* what() const throw() {
35 if( uz.get() )
36 return uz->c_str();
37 return "Kivetel";
38 }
40 virtual ~Ex() throw() {}
41 };
43 static void fn1() {
44 Ex e("alma");
45 throw e;
46 }
48 static
49 void fn2() {
50 throw Ex("korte");
51 }
53 int main() {
54 try {
55 fn1();
56 }
57 catch(exception const &e) {
58 cerr << "Hiba: " << e.what() << endl;
59 }
61 try {
62 fn2();
63 }
64 catch(exception const &e) {
65 cerr << "Hiba: " << e.what() << endl;
66 }
68 }