Platinum Partner

Adding A Stack Trace To JavaScript Errors

Basic example of adding a stack trace to JavaScript errors.


function trace(e, fn) { e.stackTrace = e.stackTrace || []; e.stackTrace.push(fn); return e; }

function d() { try { throw new Error("oh noes!"); } catch (e) { throw trace(e, "d"); } }
function c() { try { d(); } catch (e) { throw trace(e, "c"); } }
function b() { try { c(); } catch (e) { throw trace(e, "b"); } }
function a() { try { b(); } catch (e) { throw trace(e, "a"); } }

try
{
  a();
}
catch (e)
{
  alert("Error: " + e.message + "\r\n" + "Stack Trace: " + e.stackTrace.join("\r\nat "));
}
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}