DEV Community 👩‍💻👨‍💻

Discussion on: Error Handling In Javascript

mike4040 profile image
Mike Kravtsov • Edited on

Thanks, Jemie!

  1. I think that super() should be called inside constructor().
  2. Error accept only one message, better use throw new Error(`Invalid ingredients: ${ingredients}`)
  3. And what do you think about following?
} catch (e) {
  throw new Error(e)
Enter fullscreen mode Exit fullscreen mode
jamiescript profile image
Jamiebones Author

Thanks Mike for the correction. I have updated the post with your correction. Catching error by displaying the exact error message to the user or UI is not the best strategy sometimes. The error message from the code is meant for the developer so that the problem can be fixed. It is best to selectively catch errors by display user friendly message to your User Interface. The error might show some inner workings of your system that you won't want a user to ever see.