---
title: "CWE-397: Declaration of Throws for Generic Exception"
url: https://radicalnotion.ai/cwe/cwe-397
type: cwe
description: "The product throws or raises an overly broad exception that can hide important details and produce inappropriate responses to certain conditions."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-397: Declaration of Throws for Generic Exception

- **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 product throws or raises an overly broad exception that can hide important details and produce inappropriate responses to certain conditions.

## Modes of introduction

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

## Applicable platforms

**Languages:** C++ (Undetermined), C# (Undetermined), Java (Undetermined), Python (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Non-Repudiation, Other | Hide Activities, Alter Execution Logic | 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. Throwing a generic exception can hide details about unexpected adversary activities by making it difficult to properly troubleshoot error conditions during execution. |

## 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

The following method throws three types of exceptions.

Good code:

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

Bad code:

```java
public void doExchange() throws Exception {
    ...
}
```

### Example 2

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.

Bad code:

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

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.

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-221](https://radicalnotion.ai/cwe/cwe-221) | Information Loss or Omission |
| Parent | [CWE-703](https://radicalnotion.ai/cwe/cwe-703) | Improper Check or Handling of Exceptional Conditions |
| Parent | [CWE-705](https://radicalnotion.ai/cwe/cwe-705) | Incorrect Control Flow Scoping |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| 7 Pernicious Kingdoms | Overly-Broad Throws Declaration | - | - |
| The CERT Oracle Secure Coding Standard for Java (2011) | Do not throw RuntimeException, Exception, or Throwable | ERR07-J | - |
| Software Fault Patterns | Ambiguous Exception Type | SFP5 | - |
| OMG ASCSM | - | ASCSM-CWE-397 | - |
| OMG ASCRM | - | ASCRM-CWE-397 | - |
| OpenSSF Secure Coding Guide for Python | Use Specific Exception Types | pyscg-0014 | - |

## Frequently asked questions

### What is CWE-397?

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

### How is CWE-397 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-397?

Exploiting CWE-397 can lead to: Hide Activities, Alter Execution Logic.

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

---

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