The catch clause argument is always of type___________.
A.
Exception
B.
Exception but NOT including RuntimeException
C.
Throwable
D.
RuntimeException
E.
CheckedException
F.
Error
Explanation:
Because all exceptions in Java are the sub-class ofjava.lang.Exception class, you
can have a single catch block that catches an exception of type Exception only. Hence the
compiler is fooled into thinking that this block can handle any exception.
See the following example:
try
{
// …
}
catch(Exception ex)
{
// Exception handling code for ANY exception
}
You can also use the java.lang.Throwable class here, since Throwable is the parent class for the
application-specific Exception classes. However, this is discouraged in Java programming circles.
This is because Throwable happens to also be the parent class for the non-application specific
Error classes which are not meant to be handled explicitly as they are catered for by the JVM
itself.Note: The Throwable class is the superclass of all errors and exceptions in the Java language.
Only objects that are instances of this class (or one of its subclasses) are thrown by the Java
Virtual Machine or can be thrown by the Java throw statement.
A throwable contains a snapshot of the execution stack of its thread at the time it was created. It
can also contain a message string that gives more information about the error.
The explanation and the answer don’t seem to connect.
The answer says it’s “throwable” but the first paragraph of the explanation seems to suggest that “Exception” is the answer.
Confusing….which is it?