aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes IBM mock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "IBM mock" Watch "IBM mock" New topic
Author

IBM mock

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi All,
I am not clear about exceptions questions. I am appreciated if anyone can give me the answer and explanation to the following question:
With respect to Exceptions, RuntimeExceptions and Errors:
a) All may be caught using try {...} catch () {...} syntax.

b) Developers cannot create their own Error subclasses.

c) A RuntimeException must always be caught or declared as thrown by the method which raises it.

d) Non-RuntimeExceptions must always be caught or declared as thrown by the method which raises them.

e) Errors must always be caught or declared as thrown by the method which raises them.
Thank you!



Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
a) All may be caught using try {...} catch () {...} syntax.
True.
Though catching/declaring Errors and RuntimeException and its
subclasses are not enforced. ie., they are not "Checked Exceptions"
b) Developers cannot create their own Error subclasses.
False.
Write your own code. One can subclass Error. It should compile fine.
c) A RuntimeException must always be caught or declared as thrown by the method which raises it.
False.
See answer (a).
d) Non-RuntimeExceptions must always be caught or declared as thrown by the method which raises them.
Ambigous answer.
If the definition of "Non-RuntimeException" precludes Error then the answer
is right because what is then left in the exception hierarchy are the
checked exceptions. On the other hand, if Errors are included in the group,
then the answer is wrong because they are not checked exceptions.
e) Errors must always be caught or declared as thrown by the method which raises them
False.
See answers (a) and (d).
Summary -
Remember the three categories of exceptions viz.,

  • RuntimeException and its subclasses - Not checked. Need not be declared/caught.
  • Exception and its subclasses - Checked. Must be declared/caught.
  • Errors - Not checked. Need not be declared/caught.

  • Hope this helps.
    Ajith


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi,
This question asks you that whether all the exceptionsand errors could be caught using a try catch bolck (option A) .. the answer to this is No, cause you can not catch errors, the only possible answer that seems to me is that all the non-runtime exceptions need to handled in a try--catch bolck.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thanks Ajit ,
for clearing my doubts.. mike lu pls disregard my reply
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thanks a lot, Ajith
Your explanation is really helpful, now I understand how to deal with exception questions.
Thanks again!
mike
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Manish- no, you can catch Errors. It's entirely possible. It usually isn't a good idea in most cases unless you know what you're doing, but it's legal. Answer A is definitely true.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IBM mock