try-catch error handling -- display line number?

Discussion in 'Javascript' started by Kim Haines, Sep 7, 2003.

  1. Kim Haines

    Kim Haines Guest

    I need help finding where an error is occuring in my code. I use a
    try-catch block like this in my global.asa:

    try {

    //my code

    } catch (e) {
    Application('errormsg') = ("An exception occurred in the script. Error
    name: " + e.name
    + ". Error description: " + e.description
    + ". Error number: " + e.number
    + ". Error message: " + e.message); }

    And this is what is SOMETIMES returned when I display
    Application('errormsg'), the rest of the time, it works:

    An exception occurred in the script. Error name: Error. Error description:
    Path not found. Error number: -2146828212. Error message: Path not found

    But I don't know which path is not found! (I'm using the filesystem object
    and importing data from a file into SQL.) Is there a way to display the
    line number of the error or more details? Or do I just have to try to catch
    the error by going through each bit of code?
     
    Kim Haines, Sep 7, 2003
    #1
    1. Advertising

  2. "Kim Haines" <> schreef in bericht
    news:x7K6b.47128$Qy4.4271@fed1read05...
    >
    > But I don't know which path is not found! (I'm using the filesystem

    object
    > and importing data from a file into SQL.) Is there a way to display the
    > line number of the error or more details? Or do I just have to try to

    catch
    > the error by going through each bit of code?
    >


    A wild guess, but following MS's logics, try:

    + ". Error line: " + e.line


    JW
     
    Janwillem Borleffs, Sep 7, 2003
    #2
    1. Advertising

  3. Kim Haines

    Kim Haines Guest

    "Janwillem Borleffs" <> wrote in message
    news:3f5bb704$0$28892$...
    > A wild guess, but following MS's logics, try:
    >
    > + ". Error line: " + e.line


    Oh, I tried that and e.lineNumber. Both return "undefined."

    Then I read that try-catch doesn't provide a way to return the line number
    if an error occurs.

    I can't figure out which file access is causing the error, and it's
    intermittent. I guess I'll start breaking down the code bit by bit.

    Thanks.

    --k
     
    Kim Haines, Sep 8, 2003
    #3
  4. "Janwillem Borleffs" <> schreef in bericht
    news:3f5bb704$0$28892$...
    >
    > A wild guess, but following MS's logics, try:
    >
    > + ". Error line: " + e.line
    >


    No, doesn't work. When you run the following code in IE, you will see all
    the properties and line isn't one of them:

    try {
    a_fish_in_the_pool;
    } catch (e) {
    for (var i in e) alert(i + ' = ' + e);
    }

    A quick search with Google learned me that Mozilla stores the line number in
    the lineNumber property and Opera appends it to the message property.

    Perhaps you could use window.onerror instead, eg:

    window.onerror = function (err, file, line) {
    alert('The following error occured: ' + err + '\n' +
    'In file: ' + file + '\n' +
    'At line: ' + line);
    return true;
    }


    HTH,
    JW
     
    Janwillem Borleffs, Sep 8, 2003
    #4
    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. Replies:
    2
    Views:
    1,186
  2. bienwell
    Replies:
    4
    Views:
    3,885
    bienwell
    May 27, 2005
  3. Mirror
    Replies:
    6
    Views:
    712
    Jason Cavett
    Apr 5, 2007
  4. Blasting Cap

    Try-Catch error handling

    Blasting Cap, May 30, 2007, in forum: ASP .Net
    Replies:
    5
    Views:
    342
    Bjorn Sagbakken
    May 31, 2007
  5. Replies:
    7
    Views:
    147
    Thomas 'PointedEars' Lahn
    May 27, 2005
Loading...

Share This Page