File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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: 18152
    
    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: 24168
    
  30

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: throwing exception from finally block (try-finally clause without catch block)
 
Similar Threads
Is finally, really finally
exception with returns
Exceptional Handling Question
Exception handling!!
understanding try-catch block?