unnecessaryCatches
Reports catch clauses that only rethrow the caught error without modification.
✅ This rule is included in the ts logical
preset.
A catch clause that only rethrows the caught error without any modification or additional logic serves no purpose. It adds unnecessary code complexity and performance overhead without providing any benefit. Errors will propagate naturally without the catch clause, making it redundant.
Examples
Section titled “Examples”async function fetchData() { try { return await fetch("/api/data"); } catch (error) { throw error; }}
function processFile(path: string) { try { const content = readFileSync(path); return JSON.parse(content); } catch (exception) { throw exception; }}
async function fetchData() { try { return await fetch("/api/data"); } catch (error) { console.error("Failed to fetch data:", error); throw error; }}
function processFile(path: string) { try { const content = readFileSync(path); return JSON.parse(content); } catch (exception) { throw new Error(`Failed to process file ${path}`, { cause: exception }); }}
Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you have a specific need to explicitly catch and rethrow errors for documentation purposes or to maintain consistent code structure across multiple try-catch blocks, you might choose to disable this rule. However, in most cases, removing unnecessary catch clauses improves code clarity and maintainability.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noUselessCatch
- ESLint:
no-useless-catch
- Oxlint:
eslint/no-useless-catch
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.