• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how ro handle exceptions in finally block .please help me thanks inadvance
 
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
raja pulleboina
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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....
 
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic