This code example shows a handler for the
Example
Visual BasicВ | Copy Code |
---|---|
Private Sub Page_Error(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles MyBase.Error Response.Write("An application error has been logged.") ApplicationSpecificErrorLogger(Server.GetLastError().Message) Server.ClearError() End Sub private void Page_Error(object sender, EventArgs e) { Response.Write("An application error has been logged."); ApplicationSpecificErrorLogger(Server.GetLastError().Message); Server.ClearError(); } |
Compiling the Code
This example requires:
-
An ASP.NET Web page.
-
An error-logging function that is specific to your application.
Robust Programming
It is preferable to use Try/Catch blocks around any code that is subject to errors rather than rely on a page-level error handler.
You cannot display error information in a control (such as a
After handling an error, you must clear it by calling the
Security
Use the
Be sure that you do not display error information that might help malicious users compromise your application. For details, see How to: Display Safe Error Messages.