source: trunk/testcase/throw.cpp@ 834

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