forked from dr-cs/intro-oop-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleExceptions.java
More file actions
40 lines (33 loc) · 1.04 KB
/
SimpleExceptions.java
File metadata and controls
40 lines (33 loc) · 1.04 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
public class SimpleExceptions {
static void iThrowException() throws Exception {
boolean isThereAProblem = true;
// ..
if (isThereAProblem) {
Exception ex = new Exception("Thrown from iThrowExcepion()");
throw ex;
}
System.out.println("Will this line execute?");
}
static void foo() throws Exception {
//iThrowException();
throw new Throwable("");
}
public static void main(String[] args) throws Exception {
int i = 0;
try {
iThrowException();
System.out.println("Will this line execute?");
} catch (Exception e) {
System.out.println("i == " + i);
System.out.println("Caught Exception in main: " + e.getMessage());
e.printStackTrace(System.out);
}
try {
foo();
} catch (Exception e) {
System.out.println("Caught Exception in foo()'s catch block: "
+ e.getMessage());
}
foo();
}
}