Debian Codegraph @

gcc/testsuite/gdc.test/fail_compilation/fail12809.d

raw
1 // REQUIRED_ARGS: -o-
2
3 bool cond;
4
5 /*
6 TEST_OUTPUT:
7 ---
8 fail_compilation/fail12809.d(18): Error: `object.Exception` is thrown but not caught
9 fail_compilation/fail12809.d(15): Error: function `fail12809.test_finally1` may throw but is marked as `nothrow`
10 fail_compilation/fail12809.d(34): Error: `object.Exception` is thrown but not caught
11 fail_compilation/fail12809.d(38): Error: `object.Exception` is thrown but not caught
12 fail_compilation/fail12809.d(31): Error: function `fail12809.test_finally3` may throw but is marked as `nothrow`
13 ---
14 */
15 void test_finally1() nothrow
16 {
17 try
18 throw new Exception(""); // error
19 finally
20 {}
21 }
22
23 void test_finally2() nothrow
24 {
25 try
26 throw new Exception(""); // no error
27 finally
28 assert(0); // unconditional halt
29 }
30
31 void test_finally3() nothrow
32 {
33 try
34 throw new Exception(""); // error
35 finally
36 {
37 if (cond)
38 throw new Exception(""); // error
39 assert(0); // conditional halt
40 }
41 }
42
43 /*
44 TEST_OUTPUT:
45 ---
46 fail_compilation/fail12809.d(58): Error: `object.Exception` is thrown but not caught
47 fail_compilation/fail12809.d(53): Error: function `fail12809.test_finally4` may throw but is marked as `nothrow`
48 fail_compilation/fail12809.d(74): Error: `object.Exception` is thrown but not caught
49 fail_compilation/fail12809.d(78): Error: `object.Exception` is thrown but not caught
50 fail_compilation/fail12809.d(69): Error: function `fail12809.test_finally6` may throw but is marked as `nothrow`
51 ---
52 */
53 void test_finally4() nothrow
54 {
55 try
56 {}
57 finally
58 throw new Exception(""); // error
59 }
60
61 void test_finally5() nothrow
62 {
63 try
64 assert(0); // unconditional halt
65 finally
66 throw new Exception(""); // no error
67 }
68
69 void test_finally6() nothrow
70 {
71 try
72 {
73 if (cond)
74 throw new Exception(""); // error
75 assert(0); // conditional halt
76 }
77 finally
78 throw new Exception(""); // error
79 }