File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IBM mock

 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5782
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
Thanks Ajit ,
for clearing my doubts.. mike lu pls disregard my reply
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic