I want to throw some things in my JS code and I want them to be instanceof Error, but I also want to have them be something else.
In Python, typically, one would subclass Exception.
What’s the appropriate thing to do in JS?
I want to throw some things in my JS code and I want them to be instanceof Error, but I also want to have them be something else.
In Python, typically, one would subclass Exception.
What’s the appropriate thing to do in JS?
In ES6:
class MyError extends Error {
constructor(message) {
super(message);
this.name="MyError";
}
}
source