# VNX-396: Declaration of Catch for Generic Exception

A catch of Exception, RuntimeException or Throwable (Java) or Exception/bare catch (C#) whose body neither rethrows nor uses the caught exception.

| Field | Value |
|---|---|
| Rule ID | `VNX-396` |
| Severity | Low |
| SARIF level | `note` |
| Kind | `sast` |
| Languages | Java, C# |
| CWE | [CWE-396](https://cwe.mitre.org/data/definitions/396.html) |
| CAPEC | [CAPEC-66](https://capec.mitre.org/data/definitions/66.html) |
| ATT&CK | [T1190](https://attack.mitre.org/techniques/T1190/) |
| CWSS vector | `CWSS:1.0/TI:L/AP:RU/AL:S/IC:N/FC:LT/RP:RU/RL:S/AV:L/AS:N/IN:A/SC:A/BI:L/DI:H/EX:L/EC:N/P:L` |
| Tags | `error-handling` `cwe-396` |
| Source | [`internal/sast/rules/vnx-396.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-396.rego) |

## Overview

VNX-396 maps to [CWE-396: Declaration of Catch for Generic Exception](https://cwe.mitre.org/data/definitions/396.html). It reports Java `catch (Exception e)`, `catch (RuntimeException e)` and `catch (Throwable t)` (including `final` and `java.lang.` forms), and C# `catch (Exception)`, `catch (Exception ex)` and a bare `catch`, whose body neither rethrows nor references the caught exception: it is not logged, wrapped or recorded, and every failure, including unrelated programming errors, becomes the same `return null`, `return false` or flag.

Not reported: a generic catch that logs, wraps, records or rethrows (`throw;`, `throw e`), a catch of a specific type, a variable named `ignored`/`ignore`/`expected`/`unused`, an empty Java catch body (VNX-391 reports that), test files, comments and strings.

## Why this matters

A generic catch answers questions the code never asked. A lookup that fails because the database is down, because of a bug, or because the row is absent all return `null`, and the cause is lost at the one place it was known.

## What gets flagged

```java
} catch (Exception e) {          // FLAGGED: e is never used
    return null;
}
```

```csharp
catch (Exception)                // FLAGGED
{
    return null;
}
```

## Remediation

1. Catch the specific exceptions the call declares or is documented to throw.
2. If a broad boundary catch is needed, log the exception with its stack trace or wrap and rethrow it.

## References

- [CWE-396: Declaration of Catch for Generic Exception](https://cwe.mitre.org/data/definitions/396.html)
- [OWASP Top 10](https://owasp.org/www-project-top-ten/)

## Suppressing this rule

Put a `nosec` comment on the line, or on line 1 to cover the whole file. Use the comment marker of the file's language (`#`, `//`, `--` or `;`):

```text
# nosec vnx-396
// nosec vnx-396
```

Or record an ignore rule: `vulnetix ignore add --rule vnx-396 --reason "..."`. See [Suppressing findings](/sast/guides/suppressing-findings.md).
