-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionHandlingDemo.java
More file actions
35 lines (31 loc) · 1.22 KB
/
ExceptionHandlingDemo.java
File metadata and controls
35 lines (31 loc) · 1.22 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
import static java.lang.System.out;
import java.io.*;
class ExceptionHandlingDemo {
void readTextFile() throws CustomExceptionDemo {
String line = null;
String filePath = "D:\\dev\\training\\currentTraining\\codes\\Alphabet.txt";
try {
FileReader fileReader = new FileReader(filePath);
BufferedReader bufferedReader = new BufferedReader(fileReader);
while((line = bufferedReader.readLine()) != null) {
out.println(line);
}
bufferedReader.close();
} catch(FileNotFoundException err) {
// out.println("FileNotFoundException " +err);
throw new CustomExceptionDemo("file not found");
} catch (IOException err) {
// out.println("IOException " +err);
throw new CustomExceptionDemo("io exception");
}
}
public static void main(String[] args) {
ExceptionHandlingDemo exceptionDemo = new ExceptionHandlingDemo();
try {
exceptionDemo.readTextFile();
} catch(Exception er) {
out.println("Some Error" +er);
}
}
}
// FileReader --class for reading character files