xfail gnat.dg/trampoline3.adb scan-assembler-not check on hppa*-*-*
[official-gcc.git] / libphobos / testsuite / libphobos.exceptions / catch_in_finally.d
blob88bd73957dda10f72f62a2c43321f2b699721393
1 import core.stdc.stdio : fprintf, stderr;
3 class MyException : Exception
5 this() { super(typeof(this).stringof); }
8 void throw_catch()
10 try
12 throw new MyException;
14 catch (MyException)
17 catch (Exception)
19 assert(false);
23 // Test that exceptions that are entirely thrown and caught in finally blocks don't affect exception handling.
24 void test1()
26 try
28 try
30 throw new Exception("p");
32 finally
34 throw_catch();
37 catch (Exception e)
39 assert(e.msg == "p");
43 // Test that exceptions that are entirely thrown and caught in finally blocks don't interfere with chaining.
44 void test2()
46 try
48 try
50 try
52 throw new Exception("p");
54 finally
56 throw new Exception("q");
59 finally
61 throw_catch();
64 catch(Exception e)
66 assert(e.msg == "p");
67 assert(e.next.msg == "q");
68 assert(!e.next.next);
72 void test3()
74 try
76 try
78 try
80 throw new Exception("p");
82 finally
84 throw_catch();
87 finally
89 throw new Exception("q");
92 catch(Exception e)
94 assert(e.msg == "p");
95 assert(e.next.msg == "q");
96 assert(!e.next.next);
100 // Test order of exception handler operations.
101 void test4()
103 string result;
104 void throw_catch()
106 pragma(inline, false);
109 result ~= "b";
110 throw new MyException;
112 catch (MyException)
114 result ~= "c";
116 catch (Exception)
118 assert(false);
125 result ~= "a";
126 throw new Exception("");
128 finally
130 throw_catch();
133 catch(Exception e)
135 result ~= "d";
137 assert(result == "abcd");
140 void test5()
142 string result;
143 void fail()
145 result ~= "b";
146 throw new Exception("a");
149 void throw_catch()
151 pragma(inline, false);
154 fail();
156 catch(Exception e)
158 assert(e.msg == "a");
159 assert(!e.next);
160 result ~= "c";
167 result ~= "a";
168 throw new Exception("x");
170 finally
172 throw_catch();
175 catch (Exception e)
177 assert(e.msg == "x");
178 assert(!e.next);
179 result ~= "d";
181 assert(result == "abcd");
184 void main() {
185 test1();
186 test2();
187 test3();
188 test4();
189 test5();
190 fprintf(stderr, "success.\n");