← Back
javascript

Catch without parameter

If you skip the error parameter in a try/catch block, it won't complain, but it won't catch

BAD 👇 It works, but with a bug (console.log is never called)

    try {
somethingThatCanThrow()
} catch {
console.log('Something went wrong');
}

GOOD 👇 I've added a missing catch error parameter

    try {
somethingThatCanThrow()
} catch (error) {
console.log('Something went wrong');
}

A subtle bug.