You can record your own custom errors with Errorception.
You can pass error objects to Errorception by calling the _errs.push
method.
try {
var parsed = JSON.parse(someString); // Will throw if someString is invalid
} catch(e) {
_errs.push(e);
throw e; // Optional
}
Important: The error object should be an instanceof Error
. If it is not, the error object will be ignored.
While a throw
isn't strictly necessary, it's highly recommended. throw
is a useful construct, so omit it only if you know what you are doing.
You can also .push
your own custom errors. For example:
_errs.push(new Error("Something's not right"));
The advantage of using _errs.push
is that you can get stack traces for errors in certain browsers (mostly WebKit, and older versions of Chrome and Firefox). Newer browsers (newer versions of Chrome, Firefox) provide stack traces even if you don't use _errs.push
. Over time, more browsers are expected to support stack traces without the need for _errs.push
. Read more about stack traces and Errorception.