Useless Catch (Re-throws Only)
ID |
javascript.useless_catch |
Severity |
low |
Remediation Complexity |
auto_fix |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Code Smell |
Language |
JavaScript |
Tags |
code-style, dead-code |
Description
Reports catch (e) { throw e; } clauses whose only effect is to re-throw the caught error. The catch adds no behaviour over not having a catch at all — including any sibling finally block, which runs regardless of whether a catch is present.
Rationale
A catch that only rethrows:
-
hides whether the author intended to handle the error (and forgot) or genuinely wanted a no-op,
-
breaks
try/catchsymmetry — readers expect a catch to add context, retry, log, recover, or suppress, -
loses the chance to wrap the error with a domain message.
// Bad - catch is a no-op
try {
doWork();
} catch (err) {
throw err;
}
// Bad - finally still runs without the catch
try {
doWork();
} catch (e) {
throw e;
} finally {
cleanup();
}
Remediation
Either remove the catch clause entirely, or replace the bare rethrow with a real handler.
// Good - no useless catch
try {
doWork();
} finally {
cleanup();
}
// Good - real handler adds context
try {
doWork();
} catch (err) {
throw new ApplicationError("doWork failed", { cause: err });
}