CWE-397: Declaration of Throws for Generic Exception

Export to Word

Description

The product throws or raises an overly broad exceptions that can hide important details and produce inappropriate responses to certain conditions.

Extended Description

Declaring a method to throw Exception or Throwable promotes generic error handling procedures that make it difficult for callers to perform proper error handling and error recovery. For example, Java's exception mechanism makes it easy for callers to anticipate what can go wrong and write code to handle each specific exceptional circumstance. Declaring that a method throws a generic form of exception defeats this system.


ThreatScore

Threat Mapped score: 0.0

Industry: Finiancial

Threat priority: Unclassified


Observed Examples (CVEs)

Related Attack Patterns (CAPEC)

N/A


Attack TTPs

N/A

Modes of Introduction

Phase Note
Implementation N/A

Common Consequences

Potential Mitigations

Applicable Platforms


Demonstrative Examples

Intro: The following method throws three types of exceptions.

Body: While it might seem tidier to write

public void doExchange() throws IOException, InvocationTargetException, SQLException { ... }

Intro: Early versions of C++ (C++98, C++03, C++11) included a feature known as Dynamic Exception Specification. This allowed functions to declare what type of exceptions it may throw. It is possible to declare a general class of exception to cover any derived exceptions that may be thrown.

Body: In the example above, the code declares that myfunction() can throw an exception of type "std::exception" thus hiding details about the possible derived exceptions that could potentially be thrown.

int myfunction() throw(std::exception) { if (0) throw out_of_range(); throw length_error(); }

Notes

← Back to CWE list