</>
Skip to content
ASP lessons (27/40)

ASP — Error Handling

On Error Resume Next

<%
On Error Resume Next

Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "invalid connection string"

If Err.Number <> 0 Then
    Response.Write("Error: " & Err.Description)
    Err.Clear
End If

On Error GoTo 0
%>

Error Properties

PropertyDescription
NumberError code
DescriptionError message
SourceError source
HelpFileHelp file path

Custom Error Page

<!-- IIS Configuration -->
<!-- Set custom error page in IIS Manager -->

Global.asa Error Handling

<SCRIPT LANGUAGE="VBScript" RUNAT="Server">
Sub Application_OnError
    ' Log error
    Response.Write("Application error occurred")
End Sub

Sub Session_OnError
    ' Log error
    Response.Write("Session error occurred")
End Sub
</SCRIPT>

Try-Catch Pattern

<%
On Error Resume Next

' Try block
Set rs = conn.Execute(sql)

If Err.Number <> 0 Then
    ' Catch block
    Response.Write("Error: " & Err.Description)
    Err.Clear
End If

On Error GoTo 0
%>

Mini Practice

  1. Use On Error Resume Next
  2. Check error number
  3. Create custom error page
  4. Handle database errors

Up Next

Continue with ASP.NET — ASP.NET introduction.

Related Topics

Frequently Asked Questions about Error Handling

What is Error Handling in ASP?

Error Handling is a fundamental concept in ASP. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Error Handling?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Error Handling.

Why is Error Handling important in ASP?

Error Handling is essential for ASP development. Understanding this concept will help you write better code and solve real-world problems more effectively.