Assignment 5
Assignment 5
Assignment_5
Exceptions Handling
1. Explain the different types of exceptions in Java. Include checked and unchecked exceptions,
runtime exceptions, and errors in your explanation.
2. Write a Java program that demonstrates the use of try...catch...finally to handle
multiple exceptions. Include a le operation that may throw an IOException and a
mathematical operation that can throw an ArithmeticException.
3. How does Java’s exception handling mechanism improve program reliability and maintainability?
Discuss with examples.
4. What are the differences between throw and throws in Java, and how are they used in
exception handling? Illustrate your explanation with examples.
5. Create a custom exception class InvalidAgeException. Write a program that uses this
exception to check if a person is eligible to vote (age >= 18). If not, it should throw
InvalidAgeException.
6. Discuss the role of the finally block in exception handling. Can the finally block be
skipped? Explain with an example.
7. Explain how you can propagate exceptions in Java. Write a program that uses the throws
keyword to propagate a FileNotFoundException.
8. Discuss the importance of custom exception classes in large-scale applications. When should you
create your own exception subclasses? Provide an example.
9. Write a Java program that handles an exception thrown from a method using the throws
keyword. Demonstrate both the throwing and catching of exceptions.
10.Design a Java class hierarchy where a parent class method throws an exception, and a subclass
overrides the method with a different exception handling mechanism. Show how throws and
custom exceptions are used in this scenario.
fi
fi