A Java program can handle an exception in several different ways. Which of the following is not a way that a Java program could handle an exception?

A Java program can handle an exception in several different ways.  Which of the following is not a way that a Java program could handle an exception?

a)       ignore the exception
b)       handle the exception where it arose using try and catch statements
c)       propagate the exception to another method where it can be handled
d)       throw the exception to a pre-defined Exception class to be handled
e)       all of the above are ways that a Java program could handle an exception

Answer:  d.

Explanation:  A thrown exception is either caught by the current code if the code is contained inside a try statement and the appropriate catch statement is implemented, or else it is propagated to the method that invoked the method that caused the exception and caught there in an appropriate catch statement, or else it continues to be propagated through the methods in the opposite order that those methods were invoked.  This process stops however once the main method is reached.  If not caught there, the exception causes termination of the program (this would be answer a, the exception was ignored).  However, an exception is not thrown to an Exception class.


Enhancing Classes

Learn More Multiple Choice Question :