llvm.org GIT mirror llvm / 206c7d0
Add test for the last chapter of our C++ exception handling odyssey. llvmg++ now fully supports all C++ exception handling functionality. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8185 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 17 years ago
1 changed file(s) with 55 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0
1 #include
2
3 static unsigned NumAs = 0;
4
5 struct A {
6 unsigned ANum;
7 A() : ANum(NumAs++) { printf("Created A #%d\n", ANum); }
8 A(const A &a) : ANum(NumAs++) { printf("Copy Created A #%d\n", ANum); }
9 ~A() { printf("Destroyed A #%d\n", ANum); }
10 };
11
12 static bool ShouldThrow = false;
13
14 int throws()
15 try
16 {
17 if (ShouldThrow) throw 7; return 123;
18 } catch (...) {
19 printf("'throws' threw an exception: rethrowing!\n");
20 throw;
21 }
22
23 struct B {
24 A a0, a1, a2;
25 int i;
26 A a3, a4;
27
28 B();
29 ~B() { printf("B destructor!\n"); }
30 };
31
32 B::B()
33 try
34 : i(throws())
35 {
36 printf("In B constructor!\n");
37 }
38 catch (int i) {
39 printf("In B catch block with int %d: auto rethrowing\n", i);
40 }
41
42
43 int main() {
44 {
45 B b; // Shouldn't throw.
46 }
47
48 try {
49 ShouldThrow = true;
50 B b;
51 } catch (...) {
52 printf("Caught exception!\n");
53 }
54 }