Skip to content

Instantly share code, notes, and snippets.

@tai2
Created December 19, 2018 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tai2/f190c9a34c74c2ae58e91227802f8bb7 to your computer and use it in GitHub Desktop.
Save tai2/f190c9a34c74c2ae58e91227802f8bb7 to your computer and use it in GitHub Desktop.
custom error detection
class CustomError extends Error {
constructor(...args) {
super(...args)
this.name = 'CustomError'
}
}
const e1 = new CustomError('a custom error')
const e2 = new Error('a standard error')
if (e1 instanceof CustomError) {
console.log('e1 is a CustomError')
} else {
console.log('e1 is not a CustomError')
}
if (e2 instanceof CustomError) {
console.log('e2 is a CustomError')
} else {
console.log('e2 is not a CustomError')
}
// e1 is a CustomError
// e2 is not a CustomError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment