| Line |  | 
|---|
| 1 | #include <terminat.h> | 
|---|
| 2 | #include <unexpect.h> | 
|---|
| 3 | #include <iostream.h> | 
|---|
| 4 | class X { /* ... */ }; | 
|---|
| 5 | class Y { /* ... */ }; | 
|---|
| 6 | class A { /* ... */ }; | 
|---|
| 7 | // pfv type is pointer to function returning void | 
|---|
| 8 | typedef void (*pfv)(); | 
|---|
| 9 | void my_terminate() | 
|---|
| 10 | {      cout << "Call to my terminate" << endl; } | 
|---|
| 11 | void my_unexpected() | 
|---|
| 12 | {      cout << "Call to my unexpected" << endl; } | 
|---|
| 13 | void 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 | } | 
|---|
| 19 | main() | 
|---|
| 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.