title: How do I get a correct backtrace for a custom error class in NodeJS?
body: <p>My understanding for the "right" way to make a custom Error class in JavaScript is something like this:</p>
  
  <pre><code>function MyError(message) {  
      this.name = "MyError";  
      this.message = message || "Default Message";  
  }  
  MyError.prototype = new Error();  
  MyError.prototype.constructor = MyError;
  </code></pre>
  
  <p>(Code snippet mooked from <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error">https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error</a>.)</p>
  
  <p>With NodeJS, if I try to check for an error of this type like:</p>
  
  <pre><code>var err = new MyError("whoops");
  assert.ifError(err);
  </code></pre>
  
  <p>...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()".</p>
  
  <p>Is there some way that I can get the correct backtrace data for the actual error, rather than the prototype?</p>