wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes exam watch question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "exam watch question" Watch "exam watch question" New topic
Author

exam watch question

jayalakshmi charugundla
Ranch Hand

Joined: Jul 22, 2009
Posts: 57
Hi all

This question is from K&B book in the exam watch topic.

The below code won't compile. Here I will get unreported exception MyException; must be caught or declared to be thrown.

I dont understand what actually the code is telling. As I know doStuff() declaring the checked exception which is thrown by us and this method is not handling that exception

Am I right? If I am wrong please explain me what is going on in the program?




Thanks in advance,
Jaya
Hiruka Sandev
Greenhorn

Joined: Nov 22, 2009
Posts: 11
jayalakshmi charugundla wrote:
As I know doStuff() declaring the checked exception which is thrown by us and this method is not handling that exception


That is correct. 'someMethod' needs to explicitly handle the 'MyException' exception which is thrown by the 'doStuff' method.
S Bhanage
Greenhorn

Joined: Oct 28, 2009
Posts: 13
Hi,

Since MyException extends "EXCEPTION", it can be handled as:
1) Using try-catch
2) Declare in throws clause.

Your someMethod() should use either of the above step.
OR
You can extend "RuntimeException" and no need to change
any code further.

It compiles with this minor change.
Hope this is helpful to you.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: exam watch question
 
Similar Threads
Exceptions doubt
Exception question
throwing Exceptions
Exception handling throw and throws
exceptions - handle or declare rule