source: trunk/testapp/exceptions/sample.cpp

Last change on this file was 5442, checked in by sandervl, 24 years ago

* empty log message *

File size: 934 bytes
Line 
1#include <terminat.h>
2#include <unexpect.h>
3#include <iostream.h>
4class X { /* ... */ };
5class Y { /* ... */ };
6class A { /* ... */ };
7// pfv type is pointer to function returning void
8typedef void (*pfv)();
9void my_terminate()
10{ cout << "Call to my terminate" << endl; }
11void my_unexpected()
12{ cout << "Call to my unexpected" << endl; }
13void f() throw(X,Y) // f() is permitted to throw objects of class
14 // types X and Y only
15{
16 A aobj;
17 throw(aobj); // error, f() throws a class A object
18}
19main()
20{
21 pfv old_term = set_terminate(my_terminate);
22 pfv old_unex = set_unexpected(my_unexpected);
23 try{ f(); }
24 catch(X) { /* ... */ }
25 catch(Y) { /* ... */ }
26 catch (...) { /* ... */ }
27
28 set_unexpected(old_unex);
29 try { f();}
30 catch(X) { /* ... */ }
31 catch(Y) { /* ... */ }
32 catch (...) { /* ... */ }
33}
34
Note: See TracBrowser for help on using the repository browser.