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 supertype exception (ExceptionA) can catch all the subtype ex- ceptions (ExceptionB and ExceptionC). Print out a message such as "ExceptionB caught" to indicate which type of exception is caught. Name your class file as ExceptionHierarchy.java.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

this is a java program code please do the code what in the question says and please follow what in the question says and dont copy or plagarise from other sources 

PART I:
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 supertype exception (ExceptionA) can catch all the subtype ex-
ceptions (ExceptionB and ExceptionC). Print out a message such as "ExceptionB caught" to
indicate which type of exception is caught. Name your class file as ExceptionHierarchy.java.
Hints:
1. To build the exception hierarchy, ExceptionA, ExceptionB and ExceptionC may have
empty body.
2. You may use System.err.println("ExceptionB caught"); instead of
System.out.println("ExceptionB caught"); so that the message will be output in
red color and in the format of exception messages. This is a more common way to output error
messages.
PART II:
Use the exception hierarchy from PART I to demonstrate that the order of catch block is important
if you want to specifically catch every exception in the same hierarchy. In other words, now you
should be able to catch subtype exceptions (ExceptionB and ExceptionC) separately rather
than using one catch block of supertype exception (ExceptionA) as you did in PART I.
You should define a method called some Method () that can throw all three exceptions randomly.
To do this, generate a random integer of 1, 2 or 3 representing ExceptionA, ExceptionB or
ExceptionC respectively, and then throw the corresponding exception. Output the random number
in some Method () to show which type of exception is randomly generated. Invoke some Method ()
in your test program and catch all three exceptions separately in three catch blocks. In each catch
block, print out a message such as "ExceptionA caught" to indicate which type of exception is
caught. Run your program a few times to make sure that some Method () may throw different
exception for different run and you are able to catch all three types of exceptions. Name your class
file as CatchDifferentExceptions. java.
Transcribed Image Text:PART I: 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 supertype exception (ExceptionA) can catch all the subtype ex- ceptions (ExceptionB and ExceptionC). Print out a message such as "ExceptionB caught" to indicate which type of exception is caught. Name your class file as ExceptionHierarchy.java. Hints: 1. To build the exception hierarchy, ExceptionA, ExceptionB and ExceptionC may have empty body. 2. You may use System.err.println("ExceptionB caught"); instead of System.out.println("ExceptionB caught"); so that the message will be output in red color and in the format of exception messages. This is a more common way to output error messages. PART II: Use the exception hierarchy from PART I to demonstrate that the order of catch block is important if you want to specifically catch every exception in the same hierarchy. In other words, now you should be able to catch subtype exceptions (ExceptionB and ExceptionC) separately rather than using one catch block of supertype exception (ExceptionA) as you did in PART I. You should define a method called some Method () that can throw all three exceptions randomly. To do this, generate a random integer of 1, 2 or 3 representing ExceptionA, ExceptionB or ExceptionC respectively, and then throw the corresponding exception. Output the random number in some Method () to show which type of exception is randomly generated. Invoke some Method () in your test program and catch all three exceptions separately in three catch blocks. In each catch block, print out a message such as "ExceptionA caught" to indicate which type of exception is caught. Run your program a few times to make sure that some Method () may throw different exception for different run and you are able to catch all three types of exceptions. Name your class file as CatchDifferentExceptions. java.
Expert Solution
steps

Step by step

Solved in 4 steps with 6 images

Blurred answer
Knowledge Booster
Exception Handling Keywords
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education