Return Inside Finally Block
Weakness ID: 584 (Weakness Base)Status: Draft
+ Description

Description Summary

The code has a return statement inside a finally block, which will cause any thrown exception in the try block to be discarded.
+ Time of Introduction
  • Implementation
+ 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)
Example Language: Java 
try {
throw IllegalArgumentException();
finally {
return r;
+ Potential Mitigations

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

+ Relationships
NatureTypeIDNameView(s) this relationship pertains toView(s)
ChildOfCategoryCategory389Error Conditions, Return Values, Status Codes
Development Concepts (primary)699
ChildOfWeakness ClassWeakness Class705Incorrect Control Flow Scoping
Research Concepts (primary)1000
+ Content History
Modification DateModifierOrganizationSource
2008-07-01Eric DalciCigitalExternal
updated Potential Mitigations, Time of Introduction
2008-09-08CWE Content TeamMITREInternal
updated Relationships
2009-05-27CWE Content TeamMITREInternal
updated Demonstrative Examples