aspose file tools*
The moose likes Beginning Java and the fly likes throwing exception from finally block (try-finally clause without catch block) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "throwing exception from finally block (try-finally clause without catch block)" Watch "throwing exception from finally block (try-finally clause without catch block)" New topic
Author

throwing exception from finally block (try-finally clause without catch block)

Gasan Guseynov
Ranch Hand

Joined: Jan 03, 2006
Posts: 67
Hi all.

Here is the code example:



And my question is: what's happening with "e" exception? It seems that jvm completely forgot about it.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18675
    
    8

Yes, that's one way of describing it. As you found out, the exception thrown in the finally block replaces the exception thrown in the try block. There can only be one exception thrown by a method, of course, so it's necessary to choose one. The choice is: the last one thrown.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

As a result, most people consider it very bad style to throw an exception -- or allow one to be thrown -- from a finally block.


[Jess in Action][AskingGoodQuestions]
Gasan Guseynov
Ranch Hand

Joined: Jan 03, 2006
Posts: 67
Many thanks all. It's very usefull information.
 
 
subject: throwing exception from finally block (try-finally clause without catch block)