Getting a Traceback

Discussion in 'Javascript' started by Gene Wirchenko, Dec 15, 2011.

  1. 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
    Gene Wirchenko, Dec 15, 2011
    #1
    1. Advertising

  2. Gene Wirchenko

    Tim Streater Guest

    In article <>,
    Gene Wirchenko <> wrote:

    > 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).

    --
    Tim

    "That excessive bail ought not to be required, nor excessive fines imposed,
    nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
    Tim Streater, Dec 15, 2011
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Josh Close
    Replies:
    1
    Views:
    326
    Larry Bates
    Jul 23, 2004
  2. Michael P. Soulier

    getting tracebacks from traceback objects

    Michael P. Soulier, Jun 24, 2005, in forum: Python
    Replies:
    1
    Views:
    373
    Kent Johnson
    Jun 24, 2005
  3. R. Bernstein
    Replies:
    8
    Views:
    395
    R. Bernstein
    Jan 16, 2006
  4. Gabriel Genellina
    Replies:
    4
    Views:
    10,987
    JodyGnumeric
    Dec 10, 2008
  5. Jack Bates
    Replies:
    0
    Views:
    276
    Jack Bates
    May 2, 2011
Loading...

Share This Page