Error Catching

jessica200
jessica200 used Ask the Experts™
on
How do you catch errors in ASP?
For example when you try to insert into the database and it does not work, how can you catch that kind of error?
thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Use a stored procedure that returns an error message/status or use "on error resume next" and check the errors in asp.

Author

Commented:
I do not know much about stored procedures. Could you show me some code for that?

On error resume next would not server the purpose I suppose because then I would never know if the errror occured, and would not be able to do anything about it.

Is use of stored procedures the only way then?
Using a stored procedure would depend on what database you're using and are called using the ADO command object.  They're really nice to keep application logic out of your ASP interface.

To use the "on error resume next" use this after your db call.  
If Err.Number > 0 Then
     Response.Write("Error #" & Err.Number &" <br>")
     Response.Write("Error Source: " & Err.Source & "<br>")
     Response.Write("Error Description: " & Err.Description & "<br>")
     Response.end
End If
After checking you probably want an "on error resume 0" to resume normal error processing.

Commented:
just a note - joeposter649 gets the money.

<%
On Error Resume Next
'cnn.Execute(...)
If Err Then
      '...
      Response.End
End If
On Error Goto 0
%>

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial