Newer
Older
ISWB Prasetya
committed
public class XException {
public static int Uncaught(int x) {
if (x<0) throw new IllegalArgumentException() ;
x = x+1 ;
return x ;
}
ISWB Prasetya
committed
public static int WithCatch(int x) {
try {
if (x<0) throw new IOException() ;
}
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
catch (IllegalArgument e) { x=1 ; }
catch (IOException e) { x=0 ; }
x = x+1 ;
return x ;
}
public static int WithCatchButNotCaught(int x) {
try {
if (x<0) throw new IOException() ;
}
catch (IllegalArgument e) { x=1 ; }
x = x+1 ;
return x ;
}
public static int WithCatchFinally(int x) {
try {
if (x<0) throw new IOException() ;
}
catch (IllegalArgumentException e) { x=1 ; }
catch (IOException e) { x=0 ; }
finally { x=x+3 ; }
x = x+1 ;
return x ;
}
public static int WithCatchFinallyButNotCaught(int x) {
try {
if (x<0) throw new IOException() ;
}
catch (IllegalArgumentException e) { x=1 ; }
finally { x=x+3 ; }
x = x+1 ;
return x ;
}
public static int WithNestedCatch1(int x) {
try {
try {
if (x<0) throw new IOException() ;
}
catch (IllegalArgumentException e) { x=1 ; }
x = 9 ;
}
ISWB Prasetya
committed
catch (IOException e) { x=0 ; }
x = x+1 ;
return x ;
}
public static int WithNestedCatch2(int x) {
try {
try {
if (x<0) throw new IOException() ;
}
catch (IOException e) { x=0 ; }
finally { x=x+4 ; }
x = x+9 ;
}
catch (IllegalArgumentException e) { x=1 ; }
finally { x=x+3 ; }
x = x+1 ;
return x ;
}
public static int WithNestedCatch3(int x) {
try {
try {
if (x<0) throw new IOException() ;
}
catch (IllegalArgumentException e) { x=1 ; }
finally { x=x+4 ; }
x = 9 ;
}
catch (IOException e) { x=x+5 ; }
finally { x=x+3 ; }
x = x+1 ;
return x ;
}