Trap errors - 2nd post

E

Eitan

Hello,
I want to emphasize a point for my prior posts :

How can I trap a message in ASP (not dotnet), to a specific label.

(I know : on error goto my_label ...
but this does not work in ASP pages)

Thanks :)
 
B

Bob Barrows [MVP]

Eitan said:
Hello,
I want to emphasize a point for my prior posts :

How can I trap a message in ASP (not dotnet), to a specific label.

(I know : on error goto my_label ...
but this does not work in ASP pages)

Thanks :)

One of the links that was provided showed an example, but here's a generic
example:

on error resume next
'bunch of statements
'statement that may generate an error
if err <> 0 then
'handle the error
response.write err.number & ": " & err.description
'use Select Case to tailor your action to specific error numbers
end if
'turn off error handling if appropriate (this is optional*):
on error goto 0


In addition, with ADO, you also can ustilize the connection object's Errors
collection (you still have to us on error resume next)

on error resume next
conn.execute querythatmayproduceerror
if conn.Errors.count > 0 then
for each adoerr in conn.errors
response.write "<BR>ADO Error #" & adoerr.number & "<BR>" & _
"DB Error #: & ": " & adoerr.nativeError & "<BR>" & _
"Description: " ": " & adoerr.description
'use Select Case to tailor your action to specific error numbers
next
end if

Bob Barrows
 
B

Bob Barrows [MVP]

Bob said:
One of the links that was provided showed an example, but here's a
generic example:

on error resume next
'bunch of statements
'statement that may generate an error
if err <> 0 then
'handle the error
response.write err.number & ": " & err.description
'use Select Case to tailor your action to specific error numbers
end if
'turn off error handling if appropriate (this is optional*):
on error goto 0
This would be better written like this:

on error resume next
'bunch of statements whose errors you wish to ignore
....
....
....
'statement that may generate an error you wish to handle
err.clear
....
if err <> 0 then
'handle the error
response.write err.number & ": " & err.description
'use Select Case to tailor your action to specific error numbers
end if
'turn off error handling if appropriate (this is optional*):
on error goto 0

*Eric Lippert wrote a series of blogs about error-handling in vbscript,
which you can find here:
http://blogs.msdn.com/ericlippert/category/2528.aspx

Bob Barrows
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top