0% found this document useful (0 votes)
5 views

Assignment 5

Uploaded by

prachibpatel2005
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Assignment 5

Uploaded by

prachibpatel2005
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Subject Name: Object Oriented Programming with Java Subject Code:SEIT2210

Assignment_5
Exceptions Handling

Very Short Type Questions


1. What is an exception in Java?
2. Name two types of exceptions in Java.
3. What is the purpose of the finally block in exception handling?
4. What is the difference between throw and throws in Java?
5. Why would you create your own exception subclass?

Short Type Questions


1. Explain the difference between checked and unchecked exceptions. Provide examples of each.
2. Describe the structure of a try...catch...finally block and explain when each part is
executed.
3. How does the throws keyword help in exception handling? Give an example.
4. Discuss the bene ts of using custom exceptions over standard Java exceptions.
5. Explain how multiple catch blocks can be used in exception handling. What should be kept in
mind while using them?

Long Type Questions

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

You might also like