The catch clause argument is always of type___________.

The catch clause argument is always of type___________.

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 of java.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.

Incorrect answers:
A: With good programming practice Exception would be the best answer. Note: The class Exception and its subclasses are a form of Throwable that indicates conditions that a reasonable application might want to catch. Also this is the class that a programmer may want to extend when adding business logic exceptions.
D: RuntimeException is the superclass of those exceptions that can be thrown during the normal operation of the Java Virtual Machine. A method is not required to declare in its throws clause any subclasses of RuntimeException that might be thrown during the execution of the method but not caught.
F: An Error indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions.



Leave a Reply 6

Your email address will not be published. Required fields are marked *


Pranay

Pranay

Throwable.

Anything that can be caught, needs to be throwable!! 🙂

Jazz

Jazz

Throwable

Because all exceptions in Java are the sub-class ofjava.lang.Exceptionclass, you
can have a singlecatch blockthat catches an exception of typeExceptiononly. 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.

James

James

The Answer is C.

gfsaggd

gfsaggd

Answer is A. Throwable is a parent for both Error and Exception, and Error cannot be caught. So C is not correct.

Hans

Hans

You can discuss whether is’s usefull, but you can catch an error.

Connor

Connor

nfl fann shop promo code nba shop black friday promotional code promo codes
for mlb shop