---
title: "CWE-584: Return Inside Finally Block"
url: https://radicalnotion.ai/cwe/cwe-584
type: cwe
description: "The code has a return statement inside a finally block."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-584: Return Inside Finally Block

- **Abstraction:** Base
- **Structure:** Simple
- **Status:** Draft
- **CVEs with this as primary weakness:** 0
- **Of those, in CISA KEV:** 0
- **New in 2026:** 0
- **CWE catalog version:** 4.21

## Description

The code has a return statement inside a finally block.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | - |

## Applicable platforms

**Languages:** Python (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Other | Alter Execution Logic, Unexpected State, Varies by Context | With some languages, this will cause any thrown exception in the try block to be discarded. |

## Potential mitigations

### Implementation

Do not use a return statement inside the finally block. The finally block should have "cleanup" code.

## Detection methods

### Automated Static Analysis

Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

Effectiveness: High

## Demonstrative examples

### Example 1

In the following code excerpt, the IllegalArgumentException will never be delivered to the caller. The finally block will cause the exception to be discarded.

Bad code:

```java
try {
    ...
    throw IllegalArgumentException();
}
finally {
    return r;
}
```

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-705](https://radicalnotion.ai/cwe/cwe-705) | Incorrect Control Flow Scoping |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| The CERT Oracle Secure Coding Standard for Java (2011) | Do not complete abruptly from a finally block | ERR04-J | - |
| The CERT Oracle Secure Coding Standard for Java (2011) | Do not let checked exceptions escape from a finally block | ERR05-J | - |
| Software Fault Patterns | Incorrect Exception Behavior | SFP6 | - |
| OpenSSF Secure Coding Guide for Python | Preserve Exceptions in Finally Blocks | pyscg-0028 | - |

## Frequently asked questions

### What is CWE-584?

The code has a return statement inside a finally block.

### How do you prevent CWE-584?

Do not use a return statement inside the finally block. The finally block should have "cleanup" code.

### How is CWE-584 detected?

Automated Static Analysis: Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

### What are the consequences of CWE-584?

Exploiting CWE-584 can lead to: Alter Execution Logic, Unexpected State, Varies by Context.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/584.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-584). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
