Skip to content

unnecessaryCatches

Reports catch clauses that only rethrow the caught error without modification.

✅ This rule is included in the ts logical and logicalStrict presets.

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
function fetchData(): Promise<Response>
fetchData
() {
try {
return await
function fetch(input: string | URL | Request, init?: RequestInit): Promise<Response> (+1 overload)
fetch
("/api/data");
} catch (
function (local var) error: unknown
error
) {
throw
function (local var) error: unknown
error
;
}
}
function
function processFile(path: string): any
processFile
(
path: string
path
: string) {
try {
const
const content: any
content
=
const readFileSync: any
readFileSync
(
path: string
path
);
return
var JSON: JSON

An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.

JSON
.
JSON.parse(text: string, reviver?: (this: any, key: string, value: any) => any): any

Converts a JavaScript Object Notation (JSON) string into an object.

@paramtext A valid JSON string.

@paramreviver A function that transforms the results. This function is called for each member of the object. If a member contains nested objects, the nested objects are transformed before the parent object is.

@throws{SyntaxError} If text is not valid JSON.

parse
(
const content: any
content
);
} catch (
function (local var) exception: unknown
exception
) {
throw
function (local var) exception: unknown
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 ❤️‍🔥 around the world by the Flint team and contributors.