[thelist] ASP error handling - was TIP

Darren Neimke darrenn at qldstate.com.au
Fri Jun 15 20:43:43 CDT 2001


Minh Lee Goon said...

	> The other tool is (surprise) the errors collection.
Response.Write Errors.Num 
	> and Errors.Description to the page and give yourself some
useful clues.

There's not actually an Errors collection in VBScript (which is what I
presume you were using.  You need to interrogate the properties of the
Err 'Object' to get information regarding Errors that have occurred in
your scripts.  Here's a sample script which uses On Error Resume Next
and then if a 'Division by zero' occurs the ErrorHandler sub handles it
and passes back a *friendly* error to the user and continues processing.
If any other error is found then processing is halted:


<%
On Error Resume Next

sub DisplayErrorMessage()
' Error handler.
    With Response
        .Write "You recieved error number: " & Err.Number & "<br />" &
vbCrLf
        .Write "Which means: " & Err.Description & "<br />" & vbCrLf
        
            If Err.Number = 11 Then 
                Err.Clear
                Exit Sub
            Else
                .End
            End If
    End With
end sub

dim intI
' ##### Error occurs here
intI = Cint(7/0)

If Err.number <> 0 Then
    DisplayErrorMessage()
Else
    Response.Write "The value is: " & intI
End If

Response.Write "Error number is now: " & Err.Number & "."
%>


I do have a more elaborate Error handler located here:

 
http://flws.com.au/showusyourcode/codeLib/code/errHandler.asp?catID=1

But I'm not terribly sure that, that page is viewable in Netscape -
never tested it (oooops), but I'm about to start making the site
cross-browser (promise).


Cheers,
Darren




More information about the thelist mailing list