My understanding for the "right" way to make a custom Error class in JavaScript is something like this:
function MyError(message) {
this.name = "MyError";
this.message = message || "Default Message";
}
MyError.prototype = new Error();
MyError.prototype.constructor = MyError;
(Code snippet mooked from https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error.)
With NodeJS, if I try to check for an error of this type like:
var err = new MyError("whoops");
assert.ifError(err);
...the backtrace will show the context of the Error object I created at compile time to be the prototype for MyError, not the MyError object I created with "new MyError()".
Is there some way that I can get the correct backtrace data for the actual error, rather than the prototype?