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

Respuesta :

Limosa

Answer: (d) throw the exception to a pre-defined Exception class to be handled

Explanation:

Whenever we can want to throw exceptions in a program then we use throw exception These can can be arithmetic expression, null pointer exception, divide by zero exception. The exception can be thrown and the person can know where the mistake is.

There are different ways to handle an exception some of the ways are:

1. It can ignore the exception.

2. it uses try and catch statements

3. it sends the exception to be handled by another method.

But if we have already defined an exception class then we cannot throw the exception as it would be required to create object of the predefined exception class to  be able to look after the exception. Hence it will not be possible.