Empty Try Block

ID

java.empty_try_block

Severity

info

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Java

Tags

CWE:1071, reliability

Description

Reports try blocks whose body is empty.

Rationale

An empty try block is dead code: no statement can throw, so the associated catch and finally clauses will never trigger their exception-handling paths. The construct adds syntactic noise without functional value and usually indicates that the intended logic was never added.

// Bad — empty try
try {
} catch (IOException e) {
    log.error("I/O error", e);
}

Remediation

Add the intended logic or remove the empty try-catch:

// Good
try {
    processFile(path);
} catch (IOException e) {
    log.error("I/O error", e);
}