source: branches/libc-0.6/testcase/throw.cpp@ 2528

Last change on this file since 2528 was 837, checked in by bird, 22 years ago

Extended testcase.

  • Property cvs2svn:cvs-rev set to 1.4
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.9 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 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
32static foo o2(2);
33static bar o3(3);
34
35int 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 */
58 try
59 {
60 dfprintf((stderr, "foo creating\n"));
61 foo o;
62 dfprintf((stderr, "foo no throw!\n"));
63 printf("error: foo::foo() didn't throw!\n");
64 rc += o.get();
65 }
66 catch (int e)
67 {
68 dfprintf((stderr, "foo caught e=%d (ok)\n", e));
69 }
70
71
72 /* static bar - external implementation */
73 if (o3.get() == 3)
74 dfprintf((stderr, "o3 ok\n"));
75 else
76 {
77 rc++;
78 dfprintf((stderr, "o3 failed\n"));
79 }
80 try
81 {
82 rc += o3.getThrow();
83 printf("error: bar:getThrow() didn't throw!\n");
84 }
85 catch (expt e)
86 {
87 dfprintf((stderr, "foo caught e=%d (ok)\n", e.get()));
88 }
89
90 /* bar - external implementation */
91 try
92 {
93 dfprintf((stderr, "bar creating\n"));
94 bar o;
95 dfprintf((stderr, "bar no throw!\n"));
96 printf("error: bar::bar() didn't throw!\n");
97 rc += o.get();
98 }
99 catch (int e)
100 {
101 dfprintf((stderr, "bar caught e=%d (ok)\n", e));
102 }
103
104 return rc;
105}
106
Note: See TracBrowser for help on using the repository browser.