Last change
on this file since 834 was 834, checked in by bird, 22 years ago |
Extended testcase.
|
-
Property cvs2svn:cvs-rev
set to
1.2
-
Property svn:eol-style
set to
native
-
Property svn:executable
set to
*
-
Property svn:keywords
set to
Author Date Id Revision
|
File size:
1.2 KB
|
Rev | Line | |
---|
[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 | {
|
---|
[834] | 10 | fprintf(stderr, "foo::constructor 1\n");
|
---|
[575] | 11 | }
|
---|
| 12 |
|
---|
| 13 | foo() throw(int) : i(1)
|
---|
| 14 | {
|
---|
[834] | 15 | fprintf(stderr, "foo::constructor 2\n");
|
---|
[575] | 16 | throw(1);
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | int get() const
|
---|
| 20 | {
|
---|
| 21 | return i;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | };
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 | static foo o2(2);
|
---|
| 28 |
|
---|
| 29 | int main()
|
---|
| 30 | {
|
---|
[834] | 31 | int rc = 0;
|
---|
[575] | 32 |
|
---|
[834] | 33 | /* static foo - inline implementation */
|
---|
[575] | 34 | if (o2.get() == 2)
|
---|
| 35 | fprintf(stderr, "o2 ok\n");
|
---|
| 36 | else
|
---|
[834] | 37 | {
|
---|
| 38 | rc++;
|
---|
[575] | 39 | fprintf(stderr, "o2 failed\n");
|
---|
[834] | 40 | }
|
---|
[575] | 41 |
|
---|
[834] | 42 | /* foo - inline implementation */
|
---|
[575] | 43 | try
|
---|
| 44 | {
|
---|
[834] | 45 | fprintf(stderr, "foo creating\n");
|
---|
[575] | 46 | foo o;
|
---|
[834] | 47 | fprintf(stderr, "foo no throw!\n");
|
---|
| 48 | printf("error: foo::foo() didn't throw!\n");
|
---|
| 49 | rc += o.get();
|
---|
[575] | 50 | }
|
---|
| 51 | catch (int e)
|
---|
| 52 | {
|
---|
[834] | 53 | fprintf(stderr, "foo caught e=%d (ok)\n", e);
|
---|
[575] | 54 | }
|
---|
| 55 |
|
---|
[834] | 56 | /* bar - external implementation */
|
---|
| 57 | try
|
---|
| 58 | {
|
---|
| 59 | fprintf(stderr, "bar creating\n");
|
---|
| 60 | bar o;
|
---|
| 61 | fprintf(stderr, "bar no throw!\n");
|
---|
| 62 | printf("error: bar::bar() didn't throw!\n");
|
---|
| 63 | rc += o.get();
|
---|
| 64 | }
|
---|
| 65 | catch (int e)
|
---|
| 66 | {
|
---|
| 67 | fprintf(stderr, "bar caught e=%d (ok)\n", e);
|
---|
| 68 | }
|
---|
| 69 |
|
---|
[575] | 70 | return rc;
|
---|
| 71 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.