Lab6-ExceptionHandling 1
Lab6-ExceptionHandling 1
Major:AISE
1. Test running program and enter inputs in the following test cases below.
import java.util.Scanner;
Insert code using try-catch for each exception type. Test running program for each test
case. The program must print “End of program.” even an exception occurs.
1
2
3
2. Test running the code below.
import java.util.Scanner;
Insert the try-catch statement, separate catch statements according to the type of
exception to handle all possible the exceptions by showing exception name.
Answer:
4
5
6
3. From the code with throw statements. What statements cause the program
compile error? Why?
Answer: Unhandled exception: java.lang.Exception
Answer:
7
8
4. The class FileManagement is declared below. Write a Java program. In the
main method of your program, create an object of FileManagement class and
run program. What is the exception reported? Add the code to handle with that
exception.
import java.io.FileReader;
import java.io.IOException;
9
FileReader reader = null;
Answer:
10
11