1 package integrationTests.otherControlStructures;
2
3 public final class TryCatchFinallyStatements {
4 void tryCatch() {
5 try {
6 System.gc();
7 } catch (Exception e) {
8 e.printStackTrace();
9 }
10 }
11
12 boolean tryCatchWhichThrowsAndCatchesException() {
13 try {
14 throw new RuntimeException("testing");
15 } catch (RuntimeException e) {
16 return true;
17 }
18 }
19
20 int regularTryFinally(boolean b) {
21 try {
22 if (b) {
23 return 1;
24 }
25 return 0;
26 } finally {
27 System.gc();
28 }
29 }
30
31
32 boolean finallyBlockWhichCannotCompleteNormally(boolean b) {
33 while (b) {
34 try {
35 return true;
36 } finally {
37 break;
38 }
39 }
40 return false;
41 }
42
43 int whileTrueWithTryFinallyInsideAnother() {
44 int i = 0;
45 while (true) {
46 try {
47 try {
48 i = 1;
49
50 } finally {
51 i = 2;
52 }
53 i = 3;
54
55 return i;
56
57 } finally {
58 if (i == 3) {
59
60 continue;
61 }
62 }
63 }
64 }
65
66 void finallyBlockContainingIfWithBodyInSameLine() {
67 boolean b = false;
68
69 try {
70 toString();
71 } finally {
72 if (b) {
73 toString();
74 }
75 }
76 }
77 }