File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes how ro handle exceptions in finally block .please help me  thanks inadvance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how ro handle exceptions in finally block .please help me  thanks inadvance" Watch "how ro handle exceptions in finally block .please help me  thanks inadvance" New topic
Author

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

raja pulleboina
Greenhorn

Joined: Dec 10, 2009
Posts: 12
how ro handle exceptions in finally block .please help me thanks inadvance
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

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.


- Chinna
raja pulleboina
Greenhorn

Joined: Dec 10, 2009
Posts: 12
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....
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
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:


SCJP 1.6 96%
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174


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.

 
 
subject: how ro handle exceptions in finally block .please help me thanks inadvance
 
Similar Threads
Nullpointer Exception
Basic dout on EJB and JB
Purpose of Finally Block
IBATIS
Java's exceptions for total beginner