GetLastError

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.

Syntax

Server.GetLastError ()

 

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 will automatically transfer 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 the Internet Information Services snap-in.

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.

Example

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

The first example demonstrates a pre-processing error, which IIS will generate 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. The second example demonstrates a script compiling error. The scripting engine will not compile this script because it is missing the keyword "next" in a For...Next loop. The third example demonstrates a run-time error that will be caught because the script attempts to divide by 0.

Example 1

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

Example 2

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

Example 3

<%
  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

See Also

ASPError Object