What is the correct way to define a custom error in JavaScript?
Searching through SO I've found about 6 different ways to define a custom error, but I'm unsure as to the (dis)advantages to each of them.
From my (limited) understanding of prototype inheritance in JavaScript, this code should be sufficient:
function CustomError(message) {
this.name = "CustomError";
this.message = message;
}
CustomError.prototype = Object.create(Error.prototype);