Chapter 50: ASP Error
1. What is the ASPError Object? (Very Important Context)
When an unhandled runtime error happens in Classic ASP (division by zero, undefined variable with Option Explicit, database connection failure, etc.), two things normally happen:
- IIS shows the ugly yellow default error page with a description like:
- “Active Server Pages error ‘ASP 0115’”
- “Object required: ‘…’”
- “Type mismatch”
- The page stops executing immediately — no more code runs after the error line.
The ASPError object is the only built-in way Classic ASP gives you to catch that error, read its details, and show a custom friendly message (or log it) instead of letting IIS display the scary yellow screen to users.
Important facts (write these down):
- ASPError is automatically created by IIS when an error occurs
- You can only access it inside an error-handling block (On Error Resume Next + If Err.Number <> 0)
- It lives only for the current request — gone after the page finishes
- It gives you detailed information about what went wrong (line number, file, description, source code line, etc.)
2. The Main Properties of ASPError (All You Really Need)
| Property | What it returns | Most useful for |
|---|---|---|
| ASPError.ASPCode | ASP-specific error code (e.g. ‘ASP 0115’) | Identifying exact ASP error type |
| ASPError.ASPDescription | Long description (in English) | Showing to developers/support |
| ASPError.Category | Where error happened (‘ASP’, ‘Object’, ‘ODBC’, etc.) | Quick diagnosis |
| ASPError.Column | Column number in the line where error occurred | Pinpointing syntax errors |
| ASPError.Description | Short error message | User-friendly message |
| ASPError.File | Name of the .asp file where error happened | Which page crashed |
| ASPError.Line | Line number where error occurred | Most important for debugging |
| ASPError.Number | COM error number (same as Err.Number) | Checking error type |
| ASPError.Source | Actual source code line that caused the error | Extremely helpful (shows the bad line) |
3. Basic Example – Catching & Displaying ASPError Details
File: error_test.asp
|
0 1 2 3 4 5 6 |
<%@ Language=VBScript %> <% Option Explicit %> <!DOCTYPE html> <html> <head> <title>ASPError Demo</title> </head> <body> <h2>Testing ASPError Object</h2> <% On Error Resume Next ' ← MUST turn this on to catch errors ' Deliberately cause different errors Dim x x = 1 / 0 ' Division by zero (runtime error) ' If error happened, show details If Err.Number <> 0 Then Dim errObj Set errObj = Server.GetLastError ' ← this is how you get ASPError Response.Write "<div style='border:2px solid red; padding:15px; background:#fff0f0;'>" Response.Write "<h3 style='color:red;'>Server Error Occurred!</h3>" Response.Write "<p><strong>ASP Code:</strong> " & errObj.ASPCode & "</p>" Response.Write "<p><strong>Category:</strong> " & errObj.Category & "</p>" Response.Write "<p><strong>Description:</strong> " & Server.HTMLEncode(errObj.Description) & "</p>" Response.Write "<p><strong>ASP Description:</strong> " & Server.HTMLEncode(errObj.ASPDescription) & "</p>" Response.Write "<p><strong>File:</strong> " & Server.HTMLEncode(errObj.File) & "</p>" Response.Write "<p><strong>Line:</strong> " & errObj.Line & "</p>" Response.Write "<p><strong>Column:</strong> " & errObj.Column & "</p>" Response.Write "<p><strong>Number:</strong> " & errObj.Number & "</p>" Response.Write "<p><strong>Source line:</strong><br><pre>" & Server.HTMLEncode(errObj.Source) & "</pre></p>" Response.Write "</div>" Err.Clear End If On Error GoTo 0 ' ← good habit to turn off after handling %> <p>Normal page content continues...</p> </body> </html> |
What you see when you run it:
A nice red box with full details:
- ASP Code: ASP 0115
- Category: Microsoft VBScript runtime
- Description: Division by zero
- File: error_test.asp
- Line: 15
- Source line: x = 1 / 0
4. Real-World Pattern – Custom Error Page with ASPError
File: 500.asp (set as custom error page in IIS)
|
0 1 2 3 4 5 6 |
<%@ Language=VBScript %> <% Option Explicit %> <!DOCTYPE html> <html> <head> <title>Error - Something went wrong</title> <style> body { font-family: Arial; background:#f8f8f8; padding:40px; } .error-box { border:2px solid #dc3545; background:#fff5f5; padding:20px; max-width:800px; margin:auto; } h1 { color:#dc3545; } pre { background:#eee; padding:10px; overflow:auto; } </style> </head> <body> <div class="error-box"> <h1>Oops — Something went wrong!</h1> <p>Our team has been notified. Please try again later.</p> <% If Not IsEmpty(Server.GetLastError) Then Dim e Set e = Server.GetLastError %> <h3>Technical Details (for support):</h3> <p><strong>ASP Error Code:</strong> <%= e.ASPCode %></p> <p><strong>Description:</strong> <%= Server.HTMLEncode(e.Description) %></p> <p><strong>File:</strong> <%= Server.HTMLEncode(e.File) %></p> <p><strong>Line:</strong> <%= e.Line %></p> <p><strong>Source line:</strong><br><pre><%= Server.HTMLEncode(e.Source) %></pre></p> <% End If %> <p><a href="/">Back to Home</a></p> </div> </body> </html> |
How to enable in IIS (classic way):
In IIS Manager → Site → Error Pages → Edit Feature Settings → “Detailed errors for local requests, custom error pages for remote requests” or point 500 to your 500.asp.
5. Teacher Summary – ASP ASPError Object in Classic ASP
ASP ASPError object is:
- Automatically created when an unhandled runtime error occurs
- Accessed only via Server.GetLastError inside On Error Resume Next block
- Gives detailed info: error code, description, file, line number, source code line, column
- Used to: show friendly error pages, log errors, email admin, debug
- Must be handled immediately — gone after request ends
- Only works for ASP/VBScript errors — not IIS-level 500s or 404s
- Always use Server.HTMLEncode on .Description, .Source, etc. when displaying
This is how serious Classic ASP developers turned scary yellow error pages into professional-looking custom error messages — and many legacy Indian systems still use exactly this Server.GetLastError pattern in 2026.
Next class?
- Want a full custom error handler that logs to file + emails admin?
- Or how to combine ASPError with Response.Status for 500 pages?
- Or compare Classic ASP ASPError vs modern ASP.NET Core Exception Handling?
- Or move to the next W3Schools topic (ASP Cookies or ASP Sessions again)?
Just tell me — I’m here! 🚀🇮🇳 Keep learning strong, Webliance! 😊
