This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Associate Certification (OCAJP 7/8) 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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Associate Certification (OCAJP 7/8)
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: 89
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: 971
    
  47

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


Tim Driven Development
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5233
    
  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?