This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
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
posted
0
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
posted
0
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
posted
0
Thanks Ajit , for clearing my doubts.. mike lu pls disregard my reply
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted
0
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: 18670
posted
0
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.