我沒有測試過這一切,但你可以嘗試重新拋出異常。
Catch ex as exception
CreateLogFile(Ex)
Throw
End Try
然後,要處理該問題,請在解決方案中添加一個新的「全局應用程序類」。 Visual Studio應該創建一個新文件Global.asax。在其後面的代碼中,執行如下操作:
Public Class Global
Inherits System.Web.HttpApplication
Protected Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Server.Transfer("~/Error.aspx")
End Sub
End Class
這樣做的好處是它會捕獲任何未捕獲的異常。那麼,一旦在Error.aspx,或什麼:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim ex As Exception = Server.GetLastError()
If ex Is Nothing Then
'Can't determine last error
Else
ex = ex.GetBaseException()
If ex Is Nothing Then
'Can't determine last error
Else
'Display error message
End If
End If
End Sub
^出於某種原因,語法高亮顯示的javascript正在採取這些意見作爲字符串。
重要注意事項:如果您在之前的任何問題中收到的答案對您有幫助,請考慮返回並點擊答案旁邊的綠色複選標記。這會讓人們更有可能爲未來的問題提供答案。
我嘗試了整個事情併爲測試創建了一個錯誤,但無法重定向到Error頁面。我用throw語句導致了這個錯誤 - '執行子請求錯誤'。 – Ramesh 2010-03-29 08:45:13
@Ramesh我正在尋找,但似乎有幾個不同的可能原因。當你調用'Server.Transfer'時,你確定在字符串中指定的頁面是否存在? – 2010-03-29 08:58:36
不,實際上我創建了錯誤....錯誤頁面正在打開,但在另一個窗口中....爲什麼? – Ramesh 2010-03-29 09:47:58