Freigeben über


Server.GetLastError Method

The GetLastError method returns an ASPError Object describing the error condition that occurred. This method is available only before the .asp file has sent any content to the client.

GetLastError(
)

Parameters

This method has no parameters.

Return Values

This method has no return values.

Example Code

The following three examples demonstrate different errors that generate a 500;100 custom error. The three types of errors are:

  • Preprocessing errors

  • Script compiling errors

  • Run-time errors

The following example demonstrates a preprocessing error, which IIS generates when it tries to include the file. This error will be generated because the #include statement is missing the file parameter for the #include statement.

<!--#include fil=inc.h  --> 
<% 
  response.write "hello" 
%> 

The following example demonstrates a script compiling error. The scripting engine does not compile this script because it is missing the keyword next in a For...Next loop.

<% 
  dim I 
  for i=1 to 1 
  nxt 
%> 

The following example demonstrates a run-time error that occurs because the script attempts to divide by 0.

<% 
  dim i,j 
  dim sum 
  sum=0 
  j=0 
  for i=1 to 10 
    sum=sum+1 
  next 
  sum=sum/j 
%> 

Applies To

Server Object

Remarks

If a 500;100 custom error has been defined for an ASP application, it may refer to an .asp file. In this case, when an error occurs during the running of an .asp file within the application, the server automatically transfers to this ASP page via the Server.Transfer method. All of the state information from the executing ASP application will be available to the .asp file that is handling the error. In addition, the ASPError Object will be available, so you can expose the properties of the error through the .asp file that you set up to handle the error.

The default Web site is configured to use the file \iishelp\common\500-100.asp. You can either use this file for processing ASP errors, or create your own. If you want to change the .asp file for processing the 500;100 custom errors you can use IIS Manager.

Note

A 500;100 custom error will be generated if IIS encounters an error while processing either an .asp file or the application's Global.asa file.

Requirements

Client: Requires Windows XP Professional, Windows 2000 Professional, or Windows NT Workstation 4.0.

Server: Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.

Product: IIS

See Also