ASP » Server » GetLastError

Version: 3.0

Syntax:
Server.GetLastError( )

The GetLastError method returns an ASPError object that describes any pre-processing, runtime, or script compiling errors that occurred.

The GetLastError method returns an instance of the ASPError object. The ASPError object exposes (gives access to) nine read-only properties that provide detailed information about an error that has occurred.

Once an ASP file has sent content to a client, you cannot use the GetLastError method to access information about the error.

The types of errors handled by the ASPError method are called "500;100 custom errors" and there are three major types: pre-processing, runtime, and script compiling.

By default, the error information is sent to the "\iishelp\common\500-100.asp" file. This is a new file that is part of IIS version 5.0 and does not exist in earlier versions. Since you can access this file, you can customize this code to suit your programming needs.

Also, you can create your own personal, custom ASP error file by having the Internet Information Server (IIS) 5.0 redirect the 500;100 custom errors to an error file that you create. In your ASP error file, you can run any ASP code you desire.

Examples

Code:
<%
Dim objErrorInfo
Set objErrorInfo = Server.GetLastError

Response.Write("ASPCode = " & objErrorInfo.ASPCode)
Response.Write("ASPDescription = " & objErrorInfo.ASPDescription)
Response.Write("Category = " & objErrorInfo.Category)
Response.Write("Column = " & objErrorInfo.Column)
Response.Write("Description = " & objErrorInfo.Description)
Response.Write("File = " & objErrorInfo.File)
Response.Write("Line = " & objErrorInfo.Line)
Response.Write("Number = " & objErrorInfo.Number)
Response.Write("Source = " & objErrorInfo.Source)
%>
Explanation:

Here is the general concept of how to access the nine ASPError properties in an error file.