Beginning Active Server Pages

Error Handling

Error Handling in ASP pages is also somewhat limited - the only statements available to you are the On Error Resume Next and On Error Goto 0. Also bear in mind that although Err still returns the last error, Error does not return the error text. Use Err.Description instead. An example of error trapping is shown below:

On Error Resume Next
cConn.Execute ("INSERT INTO MyTable (UserName, Password) VALUES ('fred bloggs','mypassword')
If Err Then
    Response.Write "<p><font color=""#FF0000"">An error occured. Error " & Err & " : " & Err.Description & "</font></p>"
End If

This can be particularly useful when you need to trap constraint errors generated by the database.

You might also like...


About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The trouble with programmers is that you can never tell what a programmer is doing until it's too late.” - Seymour Cray