Error Catching

jessica200 used Ask the Experts™
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?
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.


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>")
End If
After checking you probably want an "on error resume 0" to resume normal error processing.

just a note - joeposter649 gets the money.

On Error Resume Next
If Err Then
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