DEV Community

Discussion on: Handling errors in TypeScript the right way

 
nbouvrette profile image
Nicolas Bouvrette

Interesting, I didn't think of trying it while writing the article but I just tried this:

try {
  throw undefined
} catch (error) {
  console.log((error as Error).message)
} finally {
  console.log('this will log');
}
console.log('code here is unreachable because "catch" threw a TypeError')
Enter fullscreen mode Exit fullscreen mode

And yes, finally will run but your application will still be unstable. I will add an edit shortly in the article to clarify that point. Thanks for the feedback