Forums Register Login

how ro handle exceptions in finally block .please help me thanks inadvance

+Pie Number of slices to send: Send
how ro handle exceptions in finally block .please help me thanks inadvance
+Pie Number of slices to send: Send
Finally block is meant for cleanup.. and there is a rare possiblity of getting an exception there.. many cases it can be ignored.
If required we can handle that exception.. the similar way of putting that code inside the try/block.

If we are ignoring the exception inside the finally block, it is better to atleast log the stack trace.
+Pie Number of slices to send: Send
hi chinna,

thanks for your update but if we have any exception in finally block how the exception will catch as the finally block is hte last executer for that thread....
+Pie Number of slices to send: Send
hi raja,

you will put the statement causing exception in try/catch block inside the finally block that is you will handle the exception normally as you do with exception outside the finally only thing is you are catching it within the finally block.

example:
+Pie Number of slices to send: Send
 

Chinna Eranna wrote:Finally block is meant for cleanup.. and there is a rare possiblity of getting an exception there..


Closing streams, database connections etc are usually done in a finally block, and the close() method of all these can throw a checked exception. It's not so rare as you think.

You are right that in most of those cases all you can do is log the exception.
+Pie Number of slices to send: Send
 


Closing streams, database connections etc are usually done in a finally block, and the close() method of all these can throw a checked exception. It's not so rare as you think.



I said getting an exception.. is rare.

I think I'll just lie down here for a second. And ponder this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1411 times.
Similar Threads
Purpose of Finally Block
Nullpointer Exception
Java's exceptions for total beginner
Basic dout on EJB and JB
IBATIS
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 00:44:06.