簡體   English   中英

ASP-經典:將錯誤描述獲取到HTML標記中

[英]ASP-Classic: Get error description into HTML tags

我如何嘗試從VB到HTML的錯誤描述?

碼:

if err then
Response.Write " :Err Information==>>"          
%>
<HTML><table><tr><td bgcolor="#FF0000"><%=err.Description%></td></tr></table></HTML>
<%
End if
On Error Goto 0

謝謝

@SearchAndResQ 沒有提到的是您的代碼失敗的原因。

這里的問題是Classic ASP將停止執行並將HTTP 500 Internal Server返回給客戶端(取決於服務器的配置方式將取決於響應的詳細程度)。

要在遇到錯誤或使用Err.Raise()手動引發錯誤時停止執行暫停,請使用On Error Resume Next 該語句告訴VBScript運行時在遇到錯誤時跳至下一行並填充Err對象。

若要捕獲此錯誤,請檢查Err.Number屬性以查看是否引發了錯誤。 完成操作后,使用On Error Goto 0將錯誤處理重置為默認狀態(停止執行錯誤)。

如果要在錯誤檢查內測試On Error Resume NextOn Error Goto 0之間的多個錯誤( If Err.number <> 0 Then ),請使用Err.Clear()重置Err對象( Err.Number = 0 )。

'We are expecting the next statement to sometimes fail so try to trap the error.
On Error Resume Next

' << Statement here you expect to error will be skipped >>

'Check whether error occurred.
If Err.Number <> 0 Then
  'An error occurred, handle it here (display message etc).

  'Error has been handled reset the Err object.
  Call Err.Clear() 'Err.Number is now 0
End If
'Stop trapping errors
On Error Goto 0

通常,腳本將在錯誤時停止執行。 要查看錯誤是什么,您必須On Error Resume Next可能引發錯誤的行之前使用On Error Resume Next ,然后檢查Err對象

例:

<%
On Error Resume Next
Dim i : i = 1/0 'division by zero should raise an error

If Err Then
'or you can check 
'If Err.number <> 0 Then
%>
    <table>
    <tr>
        <td>:Err Information==>></td>
        <td bgcolor="#FF0000"><%=err.Description%></td>
    </tr>
    </table>
<%
End If
On Error Goto 0
%>

有關ASP中錯誤處理的更多信息: 如何創建自定義ASP錯誤處理頁面

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM