Examining the Last Error (VB.net)
<%@ Page Language="VB" %> <html> <head> <title>Examining the Last Error</title> <script runat="server"> Sub CauseError(sender As Object, e As EventArgs) Dim x, y, z As Integer y = 1 z = 0 x = y / z End Sub Sub Page_Error(Source As Object, E As EventArgs) Dim LastError As Exception Dim ErrMessage As String LastError = Server.GetLastError() If Not LastError Is Nothing Then ErrMessage = LastError.Message Else ErrMessage = "No Errors" End If Response.Write("Last Error = " & ErrMessage & "<br/><br/>") Server.ClearError() End Sub </script> </head> <body> <form runat="server"> <h4><font face="verdana">Cause an Error to Occur...</font></h4> <asp:button text="CauseError" OnClick="CauseError" runat="server"/> </form> </body> </html>
1. | Get last error and clear error stack trace (C#) | ||
2. | Get string format server string (VB.net) | ||
3. | Server.ClearError (VB.net) |