Painless JavaScript Error Tracking
global
, function
& eval
Error
objects usually gives you a lot of information.DOMException
An unscientific analysis
Scorecard | |
Performance | |
Reliability | |
Low Effort | |
Rich errors | |
Coverage | |
Simplicity | |
Browser support |
My tests passed
My QA team has given a go-ahead
I haven't found any bugs yet
Scorecard | |
Performance | ✔ |
Reliability | ✔ |
Low Effort | ✔ |
Rich errors | ✘ |
Coverage | ✘ |
Simplicity | ✔ |
Browser support | ✘ |
try…catch
Or Spaghettification
var i = 0; $.ready(function() { $("#button").click(function() { alert(i++); }); });
try { var i = 0; $.ready(function() { try { $("#button").click(function() { try { alert(i++); } catch(e) { postError(e); } }); } catch(e) { postError(e); } }); } catch(e) { postError(e); }
try…catch
Scorecard | |
Performance | depends |
Reliability | ✔ |
Low Effort | ✘ |
Rich errors | ✔ |
Coverage | ✘ |
Simplicity | ✔ |
Browser support | ✔ |
try…catch
……and it's variants
try…catch
try…catch
try…catch
Scorecard | |
Performance | depends |
Reliability | ✔ |
Low Effort | ✔ |
Rich errors | ✔ |
Coverage | ✔ mostly |
Simplicity | ✘ |
Browser support | ✔ |
try…catch
try…catch
try…catch
Scorecard | |
Performance | depends |
Reliability | ✘ |
Low Effort | ✔ |
Rich errors | ✔ |
Coverage | ✔ mostly |
Simplicity | ✘ |
Browser support | ✔ |
try…catch
using atry…catch
using atry…catch
using aScorecard | |
Performance | ✘ |
Reliability | ✔ |
Low Effort | ✔ |
Rich errors | ✔ |
Coverage | ✔ mostly |
Simplicity | ✘ |
Browser support | ✔ |
try…catch
to browser methodstry…catch
to browser methodsvar old = document.addEventListener; document.addEventListener = function(evt, handler) { old.addEventListener(evt, function(evtObj) { try { handler(evtObj) } catch(e) { postError(e); } }, false); };
try…catch
to browser methodsScorecard | |
Performance | ✘ |
Reliability | ✔ |
Low Effort | ✔ |
Rich errors | ✔ |
Coverage | ✘ |
Simplicity | ✘ |
Browser support | ✔ |
window.onerror
window.onerror
window.onerror = function(message, lineNumber, file) { postError(message, lineNumber, file) }
window.onerror
Scorecard | |
Performance | depends |
Reliability | ✔ |
Low Effort | ✔ |
Rich errors | ✘ |
Coverage | ✔ |
Simplicity | ✔ |
Browser support | decent |
Epic Scorecard | ||||||
Manual | Build | Proxy | Failover | Client | onerror |
|
Performance | depends | depends | depends | ✘ | ✘ | depends |
Reliability | ✔ | ✔ | ✘ | ✔ | ✔ | ✔ |
Low Effort | ✘ | ✔ | ✔ | ✔ | ✔ | ✔ |
Rich errors | ✔ | ✔ | ✔ | ✔ | ✔ | ✘ |
Coverage | ✘ | ✔ mostly |
✔ mostly |
✔ mostly |
✘ | ✔ |
Simplicity | ✔ | ✘ | ✘ | ✘ | ✘ | ✔ |
Browser support | ✔ | ✔ | ✔ | ✔ | ✔ | decent |
window.onerror
fastvar errors = []; window.onerror = function(message, lineNumber, file) { errors.push({ message: message, lineNumber: lineNumber, file: file }); } window.addEventListener("load", function() { // Load the code to process the errors array }, false);