Skip to content

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.

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;
}
}

This rule is not configurable.

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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.