try-catch error handling -- display line number?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kim Haines

    #1

    try-catch error handling -- display line number?

    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('er rormsg') = ("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('er rormsg'), 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?


  • Janwillem Borleffs

    #2
    Re: try-catch error handling -- display line number?


    "Kim Haines" <klhaines-remove-for-spam@cox.net> schreef in bericht
    news:x7K6b.4712 8$Qy4.4271@fed1 read05...[color=blue]
    >
    > But I don't know which path is not found! (I'm using the filesystem[/color]
    object[color=blue]
    > 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[/color]
    catch[color=blue]
    > the error by going through each bit of code?
    >[/color]

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

    + ". Error line: " + e.line


    JW



    Comment

    • Kim Haines

      #3
      Re: try-catch error handling -- display line number?

      "Janwillem Borleffs" <jwb@jwbfoto.de mon.nl> wrote in message
      news:3f5bb704$0 $28892$1b62eedf @news.euronet.n l...[color=blue]
      > A wild guess, but following MS's logics, try:
      >
      > + ". Error line: " + e.line[/color]

      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


      Comment

      • Janwillem Borleffs

        #4
        Re: try-catch error handling -- display line number?


        "Janwillem Borleffs" <jwb@jwbfoto.de mon.nl> schreef in bericht
        news:3f5bb704$0 $28892$1b62eedf @news.euronet.n l...[color=blue]
        >
        > A wild guess, but following MS's logics, try:
        >
        > + ". Error line: " + e.line
        >[/color]

        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_p ool;
        } catch (e) {
        for (var i in e) alert(i + ' = ' + e[i]);
        }

        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



        Comment

        Working...