DEV Community

Discussion on: Say goodbye Trycatch Hell

Collapse
 
lexlohr profile image
Alex Lohr

There's a simple solution. Whatever you await should usually return a promise and thus can be directly caught:

// Don't
try {
  await myAsyncFn();
} catch(e) {
  console.error(e);
}

// Do
await myAsyncFn().catch(console.error);
Enter fullscreen mode Exit fullscreen mode