-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathTest.java
More file actions
64 lines (57 loc) · 1.59 KB
/
Copy pathTest.java
File metadata and controls
64 lines (57 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
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
57
58
59
60
61
62
63
64
import java.security.NoSuchAlgorithmException;
class Test {
void throwingMethod() throws Exception { }
void specificThrowingMethod() throws NoSuchAlgorithmException { }
void test() throws Exception {
try {
throwingMethod();
}
// Should not be reported; RuntimeException is not a supertype
catch (RuntimeException e) {
}
catch (NoSuchAlgorithmException e) {
// Not properly handled
}
// Should not be reported; previous catch already caught exception
catch (Exception e) {
}
try {
throwingMethod();
} catch (NoSuchAlgorithmException | IllegalStateException e) {
// Not properly handled
}
try {
specificThrowingMethod();
}
// Should not be reported; RuntimeException is not a supertype
catch (RuntimeException e) {
}
catch (Exception e) {
// Not properly handled
}
}
void testCorrect() throws Exception {
try {
throwingMethod();
} catch (NoSuchAlgorithmException e) {
// Correct, rethrows exception
throw e;
}
try {
try {
specificThrowingMethod();
} catch (Exception e) {
throw e;
}
}
// Nested try handles exception
catch (Exception e) {
}
try {
specificThrowingMethod();
} catch (Exception e) {
// Correct, rethrows exception
throw e;
}
}
}