js throw custom error
throw new Error("Error message here"); // Uncaught Error: Error message hereclass CustomError extends Error {
constructor(foo = 'bar', ...params) {
// Pass remaining arguments (including vendor specific ones) to parent constructor
super(...params)
// Maintains proper stack trace for where our error was thrown (only available on V8)
if (Error.captureStackTrace) {
Error.captureStackTrace(this, CustomError)
}
this.name = 'CustomError'
// Custom debugging information
this.foo = foo
this.date = new Date()
}
}
try {
throw new CustomError('baz', 'bazMessage')
} catch(e) {
console.error(e.name) //CustomError
console.error(e.foo) //baz
console.error(e.message) //bazMessage
console.error(e.stack) //stacktrace
}
Also in JavaScript:
- angular 9 dockerfile
- how to check if a number is negative in p5.js
- installing node on ec2 instance
- gatsbyjs image sharp
- jquery select radio by name
- how to reverse a video in js
- last element id javascript
- javascript scroll to bottom of div
- How to change htm h1 from nodejs
- picker change event react native
- how to display current date and time in angular
- declare an array nodejs
- moment for react
- react yup password with number string and uppercase
- sum elements in list with same name js
- jquery close another dialog
- formik and yup reactjs
- infinite scrolling firestore vuejs
- expo open app settings
- javascript refresh page every 30 seconds
- vanilla javascript jwt authentication laravel
- how to run commands in the command prompt using javascript
- ban someone discord js
- style cards react