Getting a Traceback


G

Gene Wirchenko

Dear JavaScripters:

One of the realities that I will have to face is program crashes
when my app is finally in use. The current, non-Web version writes a
bunch of data to a file including a traceback. How do I get a
traceback in JavaScript?

I prefer a browser-independent answer, but if it has to be for
just one browser, then for IE 9.

Note that the usual of firing up the debugger will not do. This
is so I can get debugging information from end users.

Since I will use includes, the concept of line number could get
somewhat shaky. It would be nice to also get a copy of the page. By
this, I mean the code not the display. (Is there a term for this
entity?)

Sincerely,

Gene Wirchenko
 
Ad

Advertisements

T

Tim Streater

Gene Wirchenko said:
Dear JavaScripters:

One of the realities that I will have to face is program crashes
when my app is finally in use. The current, non-Web version writes a
bunch of data to a file including a traceback. How do I get a
traceback in JavaScript?

I prefer a browser-independent answer, but if it has to be for
just one browser, then for IE 9.

Note that the usual of firing up the debugger will not do. This
is so I can get debugging information from end users.

Since I will use includes, the concept of line number could get
somewhat shaky. It would be nice to also get a copy of the page. By
this, I mean the code not the display. (Is there a term for this
entity?)

How far do you want the traceback to go? I'm not sure one can get a call
stack. As it is, I use the window.onerror method to record where an
error occurs (such as null pointer), thus:

window.onerror = function (msg, url, linenum)
{
var data = "msg=" + msg + "&url=" + url + "&linenum=" + linenum;
ajax ("myJSerror.php", data, logMessage);
return true; // Error still reported in error console
}

I had to poke around a bit to find the parameter sequence for this
method, but the above seems to be correct (in Safari at any rate). So if
there *is* a null pointer, I can construct a message that I send to a
PHP script that records it in my log file.

I believe window.onerror is pretty widely supported. I use includes too
but the line number reported still agrees with what I see in my text
editor (I tested this in Safari).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top