A frequently requested feature has been that of stack traces with errors. However, because window.onerror
, doesn't give access to an error object, it has not been possible for Errorception to capture stack traces. That's set to change today.
Starting today, you will be able to pass error objects to Errorception. An example is probably the best way to explain this.
try {
var myObject = JSON.parse(jsonString); // will break if jsonString is invalid
} catch(e) {
_errs.push(e);
throw e;
}
When you pass such errors manually to Errorception, Errorception will now be able to record the stack trace for this error. Undoubtedly, this can be very useful for debugging.
Important
- What you
push
to_errs
should be a valid Error object, that is, it should be aninstanceof Error
. - It is important that you
throw
the error right after passing it to_errs
. This is for two reasons. Firstly, you really want your program's execution to stop when you encounter an error, andthrow
is a great way to do so.Secondly, Errorception internally uses both theUpdate: Throwing errors isn't required anymore, but is highly recommended.Error
object and the data fromwindow.onerror
to capture error data. If you don'tthrow
the error, Errorception will ignore the error object.
As an additional bonus, with the exception of Firefox and Safari, you will also get the column number of your error. This is especially important since your JS is likely minified without line-breaks. This column number information is especially exciting — it's likely to guide the future features of Errorception.
Bonus: This works perfectly well with the recently launched ability to record custom information with errors. For example, in Errorception I was recently doing this (yes, Errorception uses Errorception):
try {
var myObject = JSON.parse(jsonString);
} catch(e) {
_errs.meta = {json: jsonString};
_errs.push(e);
throw e;
}