Skip to main content

JavaScript Error Handling


Error in javascript

Things don't go always well in our programs.In particular, there are situations where we may want to stop the program or inform the user if something bad happens.

An error in JavaScript is an object, which is later thrown to halt the program.To create a new error in JavaScript we call the appropriate constructor function.

For example, to create a new, generic error we can do:

const err = new Error("Something bad happened!");

When creating an error object it's also possible to omit the new keyword:

const err = Error("Something bad happened!");

Many types of errors in JavaScript

There are many types of errors in JavaScript, namely:

  • Error
  • EvalError
  • InternalError
  • RangeError
  • ReferenceError
  • SyntaxError
  • TypeError
  • URIError

[Error Handling] (https://www.valentinog.com/blog/error/)