Question: Java Programming Part1:Create an exception hierarchy of ExceptionA, ExceptionB and ExceptionC such that ExceptionB inherits from ExceptionA and ExceptionC inherits from ExceptionB. Write a test

Java Programming

Part1:Create an exception hierarchy of ExceptionA, ExceptionB and ExceptionC such that ExceptionB inherits from ExceptionA and ExceptionC inherits from ExceptionB. Write a test program to show that the catch block for exception super type can catch all the subtype exceptions.

Part 2:Use the exception hierarchy from above Question to demonstrate that the order of catch block is important if you want to specifically catch every exception in the same hierarchy. You should define a method called someMethod( ) that can throw all three exceptions randomly. Call someMethod( ) in your test program and catch all three exceptions separately. Run your program a few times to make sure that someMethod( ) may throw different exception for different run.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!