Debian Codegraph @

gcc/testsuite/gdc.test/runnable/test19317.d

raw
1 // REQUIRED_ARGS: -preview=dip1008
2 // https://issues.dlang.org/show_bug.cgi?id=19317
3
4 class MyException: Exception {
5 static int numInstances;
6 this(string msg) {
7 super(msg);
8 ++numInstances;
9 }
10
11 ~this() {
12 --numInstances;
13 }
14 }
15
16 void main() {
17 assert(MyException.numInstances == 0);
18
19 try
20 throw new MyException("oops");
21 catch(MyException _)
22 assert(MyException.numInstances == 1);
23
24 assert(MyException.numInstances == 0);
25
26 try
27 throw new MyException("oops I did it again");
28 catch(MyException)
29 assert(MyException.numInstances == 1);
30
31 assert(MyException.numInstances == 0);
32 }