File tree Expand file tree Collapse file tree 11 files changed +172
-14
lines changed Expand file tree Collapse file tree 11 files changed +172
-14
lines changed Original file line number Diff line number Diff line change 1+ CORE
2+ test.class
3+ ^VERIFICATION SUCCESSFUL$
4+ --
5+ ^warning: ignoring
6+ --
7+ This test verifies that catches are executed in the correct order
8+
Original file line number Diff line number Diff line change 1+ class A extends RuntimeException {}
2+ class B extends A {}
3+
4+ // This test verifies that catches are executed in the correct order
5+ public class test {
6+ public static void main (String args []) {
7+ int i = 0 ;
8+ try {
9+ try {
10+ throw new A ();
11+ }
12+ catch (A exc ) {
13+ i ++;
14+ throw new B ();
15+ }
16+ finally
17+ {
18+ // Make sure A threw into the catch
19+ assert (i ==1 );
20+ i ++;
21+ }
22+ }
23+ catch (B exc ) {
24+ // Make sure finally was executed
25+ assert (i ==2 );
26+ i ++;
27+ }
28+ // Make sure B was rethrown by finally
29+ assert (i ==3 );
30+ }
31+ }
Original file line number Diff line number Diff line change 1+ CORE
2+ test.class
3+ VERIFICATION SUCCESSFUL
4+ --
5+ ^warning: ignoring
6+ --
7+ Tests embedded try-catch-finally to ensure the catching order is correct
Original file line number Diff line number Diff line change 1+ import org .cprover .CProver ;
2+ class A extends RuntimeException {}
3+ class B extends A {}
4+
5+ // This test verifies that catches are executed in the correct order
6+ public class test {
7+ public static void main (String args []) {
8+ int i = 0 ;
9+ int j = 0 ;
10+ try {
11+ try {
12+ try {
13+ if (CProver .nondetBoolean ()) throw new A ();
14+ else throw new B ();
15+ }
16+ catch (B exc ) {
17+ i ++;
18+ }
19+ catch (A exc ) {
20+ i ++;
21+ throw new B ();
22+ }
23+ finally
24+ {
25+ // Make sure A threw into the catch
26+ assert (i ==1 );
27+ i ++;
28+ }
29+ assert (i ==2 );
30+ // Account for the rethrow in finally
31+ j ++;
32+ }
33+ catch (B exc ) {
34+ // Make sure finally was executed
35+ assert (i ==2 );
36+ i ++;
37+ throw new B ();
38+ }
39+ finally
40+ {
41+ assert ((i +j ) == 3 );
42+ }
43+ // Account for the rethrow in finally
44+ j ++;
45+ }
46+ catch (B exc )
47+ {
48+ i ++;
49+ }
50+ // Make sure B was rethrown by finally when A was thrown
51+ // or if B was thrown there was no rethrow
52+ assert (i +j == 4 );
53+ }
54+ }
You can’t perform that action at this time.
0 commit comments