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:

  1. IIS shows the ugly yellow default error page with a description like:
    • “Active Server Pages error ‘ASP 0115’”
    • “Object required: ‘…’”
    • “Type mismatch”
  2. 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

asp

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)

asp

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! 😊

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *