Created
December 19, 2018 05:59
-
-
Save tai2/f190c9a34c74c2ae58e91227802f8bb7 to your computer and use it in GitHub Desktop.
custom error detection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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