Skip to content

Files

Latest commit

 

History

History
35 lines (25 loc) · 611 Bytes

catch-error-name.md

File metadata and controls

35 lines (25 loc) · 611 Bytes

Pattern: Non-descriptive error parameter name in catch block

Issue: -

Description

Using clear and consistent names for error parameters in catch blocks improves code readability and debugging. Avoid using vague names like badName or _ when the error is actually used in the catch block.

Examples

Example of incorrect code:

try {
} catch (badName) {}

try {
} catch (_) {
  console.log(_);
}

promise.catch((badName) => {});

Example of correct code:

try {
} catch (error) {}

try {
} catch (_) {
  console.log(123);
}

promise.catch((error) => {});