File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Associate Certification (OCAJP 7) and the fly likes What happens if a runtime exception occured in a try-finally block? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Associate Certification (OCAJP 7)
Bookmark "What happens if a runtime exception occured in a try-finally block?" Watch "What happens if a runtime exception occured in a try-finally block?" New topic
Author

What happens if a runtime exception occured in a try-finally block?

Winston Liek
Ranch Hand

Joined: Jan 19, 2014
Posts: 86
What will happen if a runtime exception occured when executing a method in a try block but there are no catch nor declare is indicated but there is a finally block?

Will the code stop/terminate?
Tim Cooke
Bartender

Joined: Mar 28, 2008
Posts: 925
    
  44

The finally block will be executed, then the exception thrown.


Tim Driven Development
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5201
    
  12

Winston Liek wrote:Will the code stop/terminate?

That's something you can easily try yourself Creating your own code snippets to experiment a little bit provides the best learning experience. You don't learn a programming language by just reading and reading; grab some tools and get your hands dirty ;)


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What happens if a runtime exception occured in a try-finally block?