An unchecked exception occurs in a method dosomething() Should other code be added in the dosomething() method for it to compile and execute?

An unchecked exception occurs in a method dosomething()
Should other code be added in the dosomething() method for it to compile and execute?

An unchecked exception occurs in a method dosomething()
Should other code be added in the dosomething() method for it to compile and execute?

A.
The Exception must be caught

B.
The Exception must be declared to be thrown.

C.
The Exception must be caught or declared to be thrown.

D.
No other code needs to be added.

Explanation:

Valid Java programming language code must honor the Catch or Specify Requirement. This means
that code that might throw certain exceptions must be enclosed by either of the following:
* A try statement that catches the exception. The try must provide a handler for the exception, as
described in Catching and Handling Exceptions.
* A method that specifies that it can throw the exception. The method must provide a throws clause
that lists the exception, as described in Specifying the Exceptions Thrown by a Method.
Code that fails to honor the Catch or Specify Requirement will not compile.



Leave a Reply 8

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


novice

novice

Incorrect. Nothing is rrequired for unchecked exception.

Deepak

Deepak

Answer is correct i think. If exception is occuring in same methid, you need exception handling. Exception handling will not be required if this method is overridden by some other method.

Kalil Peixoto

Kalil Peixoto

The answer is D. For unchecked exceptions nothing is required.

sully

sully

Agreed answer is d

dafuq

dafuq

Question is ambiguous… “Should?” yeah probably should… does it “need” to be added to compile and execute? No!

Not sure what Oracle is expecting.

LaBarge

LaBarge

Answer is D.
The compiler does not require you to handle unchecked exceptions.
It will still compile the code if the Exception is not handled.

Martin Lee

Martin Lee

Hi, I just passed OCAJP 7 (1Z0-803) EXAM with 98%. I would like to share my exam experience with those who are going to take this exam. I learned the Mala Gupta’s book and PassLeader 1Z0-803 dumps. They were describing and explaning the key points of the exam very clearly. To be honest, I read Mala Gupta’s book mainly because of the interest how the basic things in Java are handled internally and I started to take the PassLeader 1Z0-803 dumps (http://www.passleader.com/1z0-803.html), around one week before the exam. Good luck to future Oracle exam takers!