ASP GetLastError() 方法 (ASP 3.0)


GetLastError 方法返回 ASPError 对象,描述发生错误的原因。

默认地,网站会使用文件 \iishelp\common\500-100.asp 来处理 ASP 错误。您既可以使用此文件,也可以创建自己的文件。如果您希望改变处理 500;100 custom errors 的 ASP 文件,请使用 IIS snap-in。

注意:如果在 IIS 处理 ASP 文件或应用程序的 Global.asa 时碰到错误,就会生成500;100 custom error。

注意:此方法仅在 ASP 文件发送任何内容到浏览器之前可用。

语法

  1. Server.GetLastError()

实例

实例 1

在本例中,在 IIS 试图引用文件,而 include 语句没有使用 file 参数时,错误就会发生:

  1. <!--#include f="header.inc" -->
    <%
    response.write("sometext")
    %>

实例 2

在本例中,当编译脚本时,由于关键词 "next" 被遗漏,就会发生错误:

  1. <%
    dim i
    for i=1 to 10
      ........
    nxt
    %>

实例 3

在本例中,由于脚本试图用 0 来除一个数,就会发生错误:

  1. <%
    dim i,tot,j
    i=0
    tot=0
    j=0

    for i=1 to 10
      tot=tot+1
    next

    tot=tot/j
    %>