# 5.5) Will a finally block execute even if the catch block defines a return statement?

![](/files/-La_-U0yUFeNSiCspRL2)

![](/files/-La_-d_YIyICqZNOepVb)

#### Example:

```java
import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class ReturnFromCatchBlock {
	public static void main(String[] args) {
		openFile();
	}

	private static void openFile() {
		FileInputStream fis = null;
		try {
			fis = new FileInputStream("file.txt");
		} catch (FileNotFoundException fnfe) {
			System.out.println("file not found");
			return;
		} finally {
			System.out.println("finally");
		}
		System.out.println("Next task..");

	}
}
```

![](/files/-La_0d1yd-VG_t-A-a3D)

![](/files/-La_0lTLUJ21SOKaFLpP)

![](/files/-La_0plrQdHTTwFPkcKH)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gyansetu-core-java-for-java.gitbook.io/project/exception-handling/4-what-happens-when-an-exception-is-thrown/5.5-will-a-finally-block-execute-even-if-the-catch-block-defines-a-return-statement.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
