DEV Community

Discussion on: Say goodbye Trycatch Hell

Collapse
 
sannajammeh profile image
Sanna Jammeh

It's a great solution, but it can be made even simpler. You will need another if statement to handle errors in your example. Why not just check if the promise is an error instance.

const res = await (promise).catch((e) => e).

If(res instanceof Error) {
// Handle err
}

Collapse
 
szymondziewonski profile image
Szymon Dziewoński

this exactly how I catch errors, and I was wondering whole time reading article "why is there a problem?" However I like wrapper util :)

Collapse
 
ivanzm123 profile image
Ivan Zaldivar

Mm... I've never thought about it, I like your solution. Thanks!