try-catch error handling -- display line number?

K

Kim Haines

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?
 
J

Janwillem Borleffs

Kim Haines said:
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
 
K

Kim Haines

Janwillem Borleffs said:
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
 
J

Janwillem Borleffs

Janwillem Borleffs said:
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
 

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

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top