Displaying Error Page based on the error exception?
I am using the exception catching procedure w开发者_如何学编程hich is the module to track the errors and it write the error description in a log file in the server.I want to display the error details in a common Error page which is having a multi-line textbox from the common function in the module.Is it possible to do that.If possible,How can I do that....
Try
;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;
Catch ex as exception
CreateLogFile(Ex)
End Try
The above description is the error catching portion from the code
In the module I have written the CreateLogFile function which write the log file.
I want to display the Error Page after writing the log file which should contain the error details....
Please Help...?.alt text http://file:///C:/Documents%20and%20Settings/Ramesh.DEV/Desktop/bbbb.bmp
I haven't tested all of this, but you could try re-throwing the exception.
Catch ex as exception
CreateLogFile(Ex)
Throw
End Try
Then, to handle that, add a new "Global Application Class" to your solution. Visual Studio should then create a new file, Global.asax. In its code behind, do something like:
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
The benefit of that is it will catch any uncaught exceptions. So then, once in Error.aspx, or whatever:
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
^ For some reason the syntax highlighting javascript is taking those comments as strings.
IMPORTANT NOTE: If, in any of your previous questions, you received an answer that helped you, maybe consider going back and clicking the green check mark next to that answer. It'll make people more likely to provide answers to your future questions.
After you call your CreateLogFile method, then you would issue a Response.Redirect or Server.Transfer to your error page
精彩评论