---
title: "Does finally always execute in Java?"  
description: "Does finally always execute in Java?"  
author: "Anonymous User"  
published: 2015-05-08  
updated: 2015-05-08  
canonical: https://www.mindstick.com/forum/23204/does-finally-always-execute-in-java  
category: "java"  
tags: ["exception handling", "java"]  
reading_time: 1 minute  

---

# Does finally always execute in Java?

I have a try/[catch block](https://www.mindstick.com/forum/159348/how-does-an-exception-find-the-correct-catch-block) with returns inside it. Will the [finally block](https://www.mindstick.com/articles/12106/exception-handling-in-java-guidelines-on-the-use-of-finally-block) be called?\
For example:\

```
try {      something();      return success;  }  catch (Exception e) {       return failure;  }  finally {      System.out.println("i don't know if this will get printed out.");}
```

I know I can just type this in an see what happens (which is what I'm about to do, actually) but when I googled for [answers](https://www.mindstick.com/forum/156899/salesforce-marketing-cloud-interview-questions-answers) nothing [came up](https://answers.mindstick.com/qa/41115/who-came-up-with-the-10-percent-plan-what-did-this-plan-say), so I figured I'd throw this up as a question.

## Replies

### Reply by Anonymous User

*finally* will be called.\
The only times finally won't be called are:1.if you call System.exit() or2.another thread interrupts current one or3.if the JVM crashes first \
Also, although it's bad practice, if there is a return statement within the finally [block](https://www.mindstick.com/forum/157599/explain-the-process-control-block-pcb-in-the-operating-system), it will trump any other return from the regular block. That is, the following block would return false:

```
try { return true; } finally { return false; }
```

Same thing with throwing exceptions from the finally block


---

Original Source: https://www.mindstick.com/forum/23204/does-finally-always-execute-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
