| 1 | #include <stdio.h>
|
|---|
| 2 | #include "throw.h"
|
|---|
| 3 |
|
|---|
| 4 | class foo
|
|---|
| 5 | {
|
|---|
| 6 | int i;
|
|---|
| 7 | public:
|
|---|
| 8 | foo(int i) : i(i)
|
|---|
| 9 | {
|
|---|
| 10 | dfprintf((stderr, "foo::constructor 1\n"));
|
|---|
| 11 | }
|
|---|
| 12 |
|
|---|
| 13 | foo() throw(int) : i(1)
|
|---|
| 14 | {
|
|---|
| 15 | dfprintf((stderr, "foo::constructor 2\n"));
|
|---|
| 16 | throw(1);
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | int get() const
|
|---|
| 20 | {
|
|---|
| 21 | return i;
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | int getthrow() const throw(int)
|
|---|
| 25 | {
|
|---|
| 26 | throw(2);
|
|---|
| 27 | return i;
|
|---|
| 28 | }
|
|---|
| 29 | };
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 | static foo o2(2);
|
|---|
| 33 | static bar o3(3);
|
|---|
| 34 |
|
|---|
| 35 | int main()
|
|---|
| 36 | {
|
|---|
| 37 | int rc = 0;
|
|---|
| 38 |
|
|---|
| 39 | /* static foo - inline implementation */
|
|---|
| 40 | if (o2.get() == 2)
|
|---|
| 41 | dfprintf((stderr, "o2 ok\n"));
|
|---|
| 42 | else
|
|---|
| 43 | {
|
|---|
| 44 | rc++;
|
|---|
| 45 | dfprintf((stderr, "o2 failed\n"));
|
|---|
| 46 | }
|
|---|
| 47 | try
|
|---|
| 48 | {
|
|---|
| 49 | rc += o2.getthrow();
|
|---|
| 50 | printf("error: foo::getthrow() didn't throw!\n");
|
|---|
| 51 | }
|
|---|
| 52 | catch (int e)
|
|---|
| 53 | {
|
|---|
| 54 | dfprintf((stderr, "foo caught e=%d (ok)\n", e));
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | /* foo - inline implementation */
|
|---|
|
|---|