Tuesday 19 February 2013

Error Object Compatibility Table

I've been spending some time lately studying JavaScript's Error object. These are some of my notes on Error object compatibility across browsers, in case anyone else finds this useful.

Property Google Chrome Safari Opera Firefox MSIE
name Yes Yes Yes Yes Yes
message Yes Yes Yes Yes Yes
stack Yes Yes Yes Yes Yes (IE10+)
toString() Yes Yes Yes Yes Yes
type Yes No No No No
columnNumber No No No Yes No
fileName No No No Yes No
sourceURL No Yes No No No
line No Yes No No No
lineNumber No No No Yes No
number No No No No Yes


  • Though file name is available in the .stack property, only Firefox and Safari provide this as an explicit property, and that too with different property names (FF: .fileName, Safari: .sourceURL).
  • All browsers string-format the stack subtly differently. There's no standard regarding stack formatting. Firefox has the least informative stack property. I'm going to cut Firefox some slack though, since they were the first to expose this property. That said, this might change in the future. Worth keeping an eye on this discussion.
  • Firefox doesn't provide column numbers in the stack at all. However, it does provide a .columnNumber property which is only useful for the first stack frame.
  • The .number property (IE) is practically useless. It points to IE's internal representation of errors.
  • .line (Safari) and .lineNumber (Firefox) properties give the line number of the first stack frame of the error. No one else provides a similar property, though this data is available in the .stack everywhere except Firefox.
  • The .toString() formatting seems consistent, and similar to the formatting of the error message in window.onerror. That is, it uses the format name + ": " + message. The only exception to this, of course, is that window.onerror formats errors differently when the source file has x-domain restrictions.
  • Column numbers in the .stack property are only available in IE10+ and Chrome. Opera provides a .stacktrace property in addition to .stack that has column numbers (go figure!). No other browser provides column numbers in the stack trace. As mentioned above, Firefox does provide an explicit .columnNumber property that's only useful for the first stack frame.
  • No stack support for IE<10. Nothing. Zilch.