Question
Which statement about the following exception statement is correct?
throw new NullPointerException();
- A. The code where this is called must include a try-catch block that handles this exception.
- B. The method where this is called must declare a compatible exception.
- C. This exception cannot be handled.
- D. This exception can be handled with a try-catch block or ignored altogether by the surrounding method.
D.
Note
A NullPointerException is an unchecked exception.
While it can be handled by the surrounding method, either through a try-catch block or included in the method declaration, these are optional.
Option D is correct.
PreviousNextRelated