VB.Net - Page_error doesn't fire.

  • Thread starter Thread starter Jay Allard
  • Start date Start date
J

Jay Allard

Hello

I'm stuck. Why doesn't this work?

Short
-----
Protected Sub Page_Error(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Error
Response.Write("An errror occurred: ")
End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Throw New Exception("hi")
End Sub

The exception gets thrown but not caught. The Page_Error handler isn't
hit.

Thanks for the help.

Jay



Full
----
Public Class ErrorPage2
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "



'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Protected Sub Page_Error(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Error
Response.Write("An errror occurred: ")
End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Throw New Exception("hi")
End Sub

End Class
 
It probably is hit. However, you are not clearing out the error by calling
Server.ClearError(). So, your handler fires, but because the error isn't
cleared out, the default mechanism kicks in anyway.
 
Wow... That's weird. So what you're saying is that if I do it correctly
as documented, it will work. Interesting. I thought I could just skip
random method calls and everything would be fine.

You were, as you know, correct. It works beautifully. Now I'm trying to
find a way that I can blame that on anything aside from my oversight. If
you have any suggestions, let me know.

Thank you for the fast response.

Jay
 
Back
Top