SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
Ankit Garg wrote:Yes you can return a value in try, catch and finally block. You just need to remember that finally block will always be executed...
SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
Lukas Smith wrote:
Ankit Garg wrote:Yes you can return a value in try, catch and finally block. You just need to remember that finally block will always be executed...
Not at all. System.exit(0) will cause that finally will not be executed and internal error/exception of JVM can cause the same![]()
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Shanmuga Priya wrote:And also finally will suppress any return in catch block.. For instance the below code will print 5.
SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
Ankit Garg wrote:
Lukas Smith wrote:
Ankit Garg wrote:Yes you can return a value in try, catch and finally block. You just need to remember that finally block will always be executed...
Not at all. System.exit(0) will cause that finally will not be executed and internal error/exception of JVM can cause the same![]()
But you don't need to worry about that in SCJP...
SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ankit Garg wrote:I was only trying to say that I've never seen a question combining try catch block and System.exit. So generally you can say that finally block is sure to be executed...
PS: Bert can confirm on that more...
SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
Lukas Smith wrote:It is OK to write return in try{}catch{}finally{} block. We can write return; (when a function is declared as void) or return typeValue; (when a function is declared as not void).
Lukas Smith wrote:
Ankit Garg wrote:
Lukas Smith wrote:
Ankit Garg wrote:Yes you can return a value in try, catch and finally block. You just need to remember that finally block will always be executed...
Not at all. System.exit(0) will cause that finally will not be executed and internal error/exception of JVM can cause the same![]()
But you don't need to worry about that in SCJP...
System.exit(0) can be tested during SCJP. Stay tuned.
Thanks,
~ Vinay Ds
System.exit(0) makes control to return without executing finally block (Which is having return statement). So now there is no return value, why doesn't compiler throws an error ?
SCJP 6
Thanks,
~ Vinay Ds
Ok. Thats fine. But my question is , compiler sees that test method return type is "int". But there is no "return" statement gets called here. So Why compiler doesn't say like "return statement is missing" ?
SCJP 6
Don't get me started about those stupid light bulbs. |