Empty Exception Block

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


Description

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.

Demonstrations

The following examples help to illustrate the nature of this weakness and describe methods or techniques which can be used to mitigate the risk.

Note that the examples here are by no means exhaustive and any given weakness may have many subtle varieties, each of which may require different detection methods or runtime controls.

Example One

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

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.

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;

    }

  }

}

See Also

Comprehensive Categorization: Poor Coding Practices

Weaknesses in this category are related to poor coding practices.

CISQ Quality Measures (2016) - Reliability

Weaknesses in this category are related to the CISQ Quality Measures for Reliability, as documented in 2016 with the Automated Source Code CISQ Reliability Measure (AS...

Comprehensive CWE Dictionary

This view (slice) covers all the elements in CWE.

Quality Weaknesses with Indirect Security Impacts

CWE identifiers in this view (slice) are quality issues that only indirectly make it easier to introduce a vulnerability and/or make the vulnerability more difficult t...


Common Weakness Enumeration content on this website is copyright of The MITRE Corporation unless otherwise specified. Use of the Common Weakness Enumeration and the associated references on this website are subject to the Terms of Use as specified by The MITRE Corporation.