forked from zouldapp/JavaWorkshopCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExceptionExample.java
36 lines (26 loc) · 919 Bytes
/
ExceptionExample.java
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
import java.io.*;
class ExceptionExample {
public InputStream fallingBlocks() throws FileNotFoundException {
String fileName = "./README.txt";
InputStream inputStream = new FileInputStream(fileName);
return inputStream;
}
public void foo() {
// doStaff
try {
fallingBlocks();
System.out.println("It works!!!");
} catch (FileNotFoundException ee) {
System.out.println("Handle the exception");
// Handle the exception
} finally {
System.out.println("finally block is always executed. cleanup: closing connection, stream etc.");
// finally block is always executed
// cleanup: closing connection, stream etc.
}
}
public static void main(String[] args) {
ExceptionExample example = new ExceptionExample();
example.foo();
}
}