| [575] | 1 | #include <stdio.h> | 
|---|
| [834] | 2 | #include "throw.h" | 
|---|
| [575] | 3 |  | 
|---|
|  | 4 | class foo | 
|---|
|  | 5 | { | 
|---|
|  | 6 | int     i; | 
|---|
|  | 7 | public: | 
|---|
|  | 8 | foo(int i) : i(i) | 
|---|
|  | 9 | { | 
|---|
| [837] | 10 | dfprintf((stderr, "foo::constructor 1\n")); | 
|---|
| [575] | 11 | } | 
|---|
|  | 12 |  | 
|---|
|  | 13 | foo() throw(int) : i(1) | 
|---|
|  | 14 | { | 
|---|
| [837] | 15 | dfprintf((stderr, "foo::constructor 2\n")); | 
|---|
| [575] | 16 | throw(1); | 
|---|
|  | 17 | } | 
|---|
|  | 18 |  | 
|---|
|  | 19 | int get() const | 
|---|
|  | 20 | { | 
|---|
|  | 21 | return i; | 
|---|
|  | 22 | } | 
|---|
|  | 23 |  | 
|---|
| [835] | 24 | int getthrow() const throw(int) | 
|---|
|  | 25 | { | 
|---|
|  | 26 | throw(2); | 
|---|
|  | 27 | return i; | 
|---|
|  | 28 | } | 
|---|
| [575] | 29 | }; | 
|---|
|  | 30 |  | 
|---|
|  | 31 |  | 
|---|
|  | 32 | static foo  o2(2); | 
|---|
| [835] | 33 | static bar  o3(3); | 
|---|
| [575] | 34 |  | 
|---|
|  | 35 | int main() | 
|---|
|  | 36 | { | 
|---|
| [834] | 37 | int rc = 0; | 
|---|
| [575] | 38 |  | 
|---|
| [834] | 39 | /* static foo - inline implementation */ | 
|---|
| [575] | 40 | if (o2.get() == 2) | 
|---|
| [837] | 41 | dfprintf((stderr, "o2 ok\n")); | 
|---|
| [575] | 42 | else | 
|---|
| [834] | 43 | { | 
|---|
|  | 44 | rc++; | 
|---|
| [837] | 45 | dfprintf((stderr, "o2 failed\n")); | 
|---|
| [834] | 46 | } | 
|---|
| [835] | 47 | try | 
|---|
|  | 48 | { | 
|---|
|  | 49 | rc += o2.getthrow(); | 
|---|
|  | 50 | printf("error: foo::getthrow() didn't throw!\n"); | 
|---|
|  | 51 | } | 
|---|
|  | 52 | catch (int e) | 
|---|
|  | 53 | { | 
|---|
| [837] | 54 | dfprintf((stderr, "foo caught e=%d (ok)\n", e)); | 
|---|
| [835] | 55 | } | 
|---|
| [575] | 56 |  | 
|---|
| [834] | 57 | /* foo - inline implementation */ | 
|---|
| [575] | 58 | try | 
|---|
|  | 59 | { | 
|---|
| [837] | 60 | dfprintf((stderr, "foo creating\n")); | 
|---|
| [575] | 61 | foo o; | 
|---|
| [837] | 62 | dfprintf((stderr, "foo no throw!\n")); | 
|---|
| [834] | 63 | printf("error: foo::foo() didn't throw!\n"); | 
|---|
|  | 64 | rc += o.get(); | 
|---|
| [575] | 65 | } | 
|---|
|  | 66 | catch (int e) | 
|---|
|  | 67 | { | 
|---|
| [837] | 68 | dfprintf((stderr, "foo caught e=%d (ok)\n", e)); | 
|---|
| [575] | 69 | } | 
|---|
|  | 70 |  | 
|---|
| [835] | 71 |  | 
|---|
|  | 72 | /* static bar - external implementation */ | 
|---|
|  | 73 | if (o3.get() == 3) | 
|---|
| [837] | 74 | dfprintf((stderr, "o3 ok\n")); | 
|---|
| [835] | 75 | else | 
|---|
|  | 76 | { | 
|---|
|  | 77 | rc++; | 
|---|
| [837] | 78 | dfprintf((stderr, "o3 failed\n")); | 
|---|
| [835] | 79 | } | 
|---|
|  | 80 | try | 
|---|
|  | 81 | { | 
|---|
|  | 82 | rc += o3.getThrow(); | 
|---|
|  | 83 | printf("error: bar:getThrow() didn't throw!\n"); | 
|---|
|  | 84 | } | 
|---|
|  | 85 | catch (expt e) | 
|---|
|  | 86 | { | 
|---|
| [837] | 87 | dfprintf((stderr, "foo caught e=%d (ok)\n", e.get())); | 
|---|
| [835] | 88 | } | 
|---|
|  | 89 |  | 
|---|
| [834] | 90 | /* bar - external implementation */ | 
|---|
|  | 91 | try | 
|---|
|  | 92 | { | 
|---|
| [837] | 93 | dfprintf((stderr, "bar creating\n")); | 
|---|
| [834] | 94 | bar o; | 
|---|
| [837] | 95 | dfprintf((stderr, "bar no throw!\n")); | 
|---|
| [834] | 96 | printf("error: bar::bar() didn't throw!\n"); | 
|---|
|  | 97 | rc += o.get(); | 
|---|
|  | 98 | } | 
|---|
|  | 99 | catch (int e) | 
|---|
|  | 100 | { | 
|---|
| [837] | 101 | dfprintf((stderr, "bar caught e=%d (ok)\n", e)); | 
|---|
| [834] | 102 | } | 
|---|
|  | 103 |  | 
|---|
| [575] | 104 | return rc; | 
|---|
|  | 105 | } | 
|---|
| [837] | 106 |  | 
|---|