Forums Register Login

try/catch/finally..................

+Pie Number of slices to send: Send
I guess I have posted a lot many questions
I found this question in Javaprepare mock exams. But I have certain doubts
59) Which of these statements are true. Select all correct answers.
A] For each try block there must be at least one catch block defined. //false
B] A try block may be followed by any number of finally blocks. //false only one finally allowed
C] A try block must be followed by at least one finally or catch block. //it should be false
it should be phrased as "A try Block must be followed by at most one finally or zero or more catch blocks." of course finally should be last.
D] If both catch and finally blocks are defined, catch block must precede the finally block //true finally must come last
Given ans : C, D
My ans : Only D for the above reasons.
Am I right? or probably the third is not phrased correctly.
Any Comments....
+Pie Number of slices to send: Send
HI Amit,
C is correct. A try can't stand by itself, it has to be followed either by exactly one finally or one or more catch clauses.
Cheers.

Originally posted by Amit Punjwani:
I guess I have posted a lot many questions
C] A try block must be followed by at least one finally or catch block. //it should be false
it should be phrased as "A try Block must be followed by at most one finally or zero or more catch blocks." of course finally should be last.
Am I right? or probably the third is not phrased correctly.
Any Comments....


+Pie Number of slices to send: Send
Hi Amit,
Check out the following site http://www.geocities.com/SiliconValley/Network/3693/obj_sec2.html#obj7
It gives a good idea of the try -catch block.
Hope it helps
Ira
Been there. Done that. Went back for more. But this time, I took this tiny ad with me:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 720 times.
Similar Threads
try-catch statement
try-catch-finally
try {} catch() {} finally {}
catch{} blocks
try/catch/finally
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 03:50:09.