# no-useless-catch

> Disallow `catch` clauses that only rethrow the error

A `catch` that starts by throwing the error it caught does the same thing as no `catch` at all. The error reaches the caller either way, and the `try` only adds nesting.

This rule is on by default.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

On by default as a warning. To turn it off:

```toml bunfig.toml
[lint.rules]
"no-useless-catch" = "off" # or "error"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
try {
  await save(user);
} catch (error) {
  throw error;
}
```

Not reported:

{/* good */}
```js
await save(user);
```

With a `finally`, only the `catch` clause is unnecessary:

{/* bad */}
```js
try {
  await save(user);
} catch (error) {
  throw error;
} finally {
  unlock(user);
}
```

{/* good */}
```js
try {
  await save(user);
} finally {
  unlock(user);
}
```

A `catch` that does something first, or throws a different error, is fine:

{/* good */}
```js
try {
  await save(user);
} catch (error) {
  log(error);
  throw error;
}

try {
  await save(user);
} catch (error) {
  throw new Error("could not save", { cause: error });
}
```
