src/content/docs/linter/rules/no-useless-catch.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.0.0` - Diagnostic Category: [`lint/complexity/noUselessCatch`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule has an [**unsafe**](/linter/#unsafe-fixes) fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`no-useless-catch`](https://eslint.org/docs/latest/rules/no-useless-catch){
"linter": {
"rules": {
"complexity": {
"noUselessCatch": "error"
}
}
}
}
Disallow unnecessary catch clauses.
A catch clause that only rethrows the original error is redundant,
and has no effect on the runtime behavior of the program.
These redundant clauses can be a source of confusion and code bloat,
so it’s better to disallow these unnecessary catch clauses.
try {
doSomething();
} catch(e) {
throw e;
}
try {
doSomething();
} catch(e) {
throw e;
} finally {
doCleanUp();
}
try {
doSomething();
} catch(e) {
doSomethingWhenCatch();
throw e;
}
try {
doSomething();
} catch(e) {
handleError(e);
}
try {
doSomething();
} finally {
doCleanUp();
}