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
| Property | Description |
|---|---|
| Number | Error code |
| Description | Error message |
| Source | Error source |
| HelpFile | Help 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
- Use On Error Resume Next
- Check error number
- Create custom error page
- 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.