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 檔發送任何內容到流覽器之前可用。
語法
Server.GetLastError()
實例
實例 1
在本例中,在 IIS 試圖引用檔,而 include 語句沒有使用 file 參數時,錯誤就會發生:
<!--#include f="header.inc" -->
<%
response.write("sometext")
%>
<%
response.write("sometext")
%>
實例 2
在本例中,當編譯腳本時,由於關鍵字 "next" 被遺漏,就會發生錯誤:
<%
dim i
for i=1 to 10
........
nxt
%>
dim i
for i=1 to 10
........
nxt
%>
實例 3
在本例中,由於腳本試圖用 0 來除一個數,就會發生錯誤:
<%
dim i,tot,j
i=0
tot=0
j=0
for i=1 to 10
tot=tot+1
next
tot=tot/j
%>
dim i,tot,j
i=0
tot=0
j=0
for i=1 to 10
tot=tot+1
next
tot=tot/j
%>
