CWE-1069

Empty Exception Block. [Improper-Adherence-To-Coding-Standards]

Required inputs: IR

An invokable code block contains an exception handling block that does not contain any code, i.e. is empty.

When an exception handling block (such as a Catch and Finally block) is used, but that block is empty, this can prevent the product from running reliably. If the relevant code is reachable by an attacker, then this reliability problem might introduce a vulnerability.

Demonstrative Examples
Example 1

In the following Java example, the code catches an ArithmeticException.

Example Language:Java (Unsupported language for documentation only)
    public class Main {

        public static void main(String[] args) {
            int a = 1;
            int b = 0;
            int c = 0;

            try {
                c = a / b;

            } catch(ArithmeticException ae) {
            }

        }

    }

Since the exception block is empty, no action is taken.

In the code below the exception has been logged and the bad execution has been handled in the desired way allowing the program to continue in an expected way.

Example Language:Java (Unsupported language for documentation only)
    public class Main {

        public static void main(String[] args) {
            int a = 1;
            int b = 0;
            int c = 0;

            try {
                c = a / b;

            } catch(ArithmeticException ae) {
                log.error("Divided by zero detected, setting to -1.");
                c = -1;

            }

        }

    }
Excerpts from CWE [https://cwe.mitre.org], Copyright (C) 2006-2026, the MITRE Corporation. See section 9.4. "3rd-Party Licenses" in the documentation for full details.

Possible Messages

Key

Text

Severity

Disabled

empty_catch

Empty catch block.

None

False

Options

allow_empty_blocks_including_comment

allow_empty_blocks_including_comment : bool = False

Whether empty blocks are allowed as long as they contain a comment.