---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 24 Edition"
java_version: 24
chapter: "Chapter 16. Definite Assignment"
section: "16.2.15"
heading: "16.2.15. try Statements"
parent: "16.2. Definite Assignment and Statements"
source: https://docs.oracle.com/javase/specs/jls/se24/html/jls-16.html#jls-16.2.15
id: "16.2.15"
url: https://jvm.obfuscated.software/jls/se24/16.2.15.html
raw: https://jvm.obfuscated.software/jls/se24/16.2.15.md
---

# 16.2.15. `try` Statements

The rules herein cover the `try`-`catch` and `try`-`catch`-`finally` statements ([§14.20.1](14.20.1.md), [§14.20.2](14.20.2.md)). Since the `try`-with-resources statement ([§14.20.3](14.20.3.md)) is defined by translation to a `try`-`catch`-`finally` statement, no special rules need to be provided for it.

These rules apply to every `try` statement ([§14.20](14.20.md)), whether or not it has a `finally` block:

- V is [un]assigned before the `try` block iff V is [un]assigned before the `try` statement.

- V is definitely assigned before a `catch` block iff V is definitely assigned before the `try` block.

- V is definitely unassigned before a `catch` block iff all of the following are true:

  - V is definitely unassigned after the `try` block.
  - V is definitely unassigned before every `return` statement that belongs to the `try` block.
  - V is definitely unassigned after `e` in every statement of the form `throw` `e` that belongs to the `try` block.
  - V is definitely unassigned after every `assert` statement that occurs in the `try` block.
  - V is definitely unassigned before every `break` statement that belongs to the `try` block and whose break target contains (or is) the `try` statement.
  - V is definitely unassigned before every `continue` statement that belongs to the `try` block and whose continue target contains the `try` statement.

If a `try` statement does not have a `finally` block, then this rule also applies:

- V is [un]assigned after the `try` statement iff V is [un]assigned after the `try` block and V is [un]assigned after every `catch` block in the `try` statement.

If a `try` statement does have a `finally` block, then these rules also apply:

- V is definitely assigned after the `try` statement iff at least one of the following is true:

  - V is definitely assigned after the `try` block and V is definitely assigned after every `catch` block in the `try` statement.
  - V is definitely assigned after the `finally` block.

- V is definitely unassigned after the `try` statement iff V is definitely unassigned after the `finally` block.

- V is definitely assigned before the `finally` block iff V is definitely assigned before the `try` statement.

- V is definitely unassigned before the `finally` block iff all of the following are true:

  - V is definitely unassigned after the `try` block.
  - V is definitely unassigned before every `return` statement that belongs to the `try` block.
  - V is definitely unassigned after `e` in every statement of the form `throw` `e` that belongs to the `try` block.
  - V is definitely unassigned after every `assert` statement that occurs in the `try` block.
  - V is definitely unassigned before every `break` statement that belongs to the `try` block and whose break target contains (or is) the `try` statement.
  - V is definitely unassigned before every `continue` statement that belongs to the `try` block and whose continue target contains the `try` statement.
  - V is definitely unassigned after every `catch` block of the `try` statement.
