我有一个 ASP.NET 页面,其中包含许多如下所示的事件处理程序:
Private Sub btnNextEvent_Click(sender As Object, e As EventArgs) Handles btnNextEvent.Click
Try
NextRegistration()
Catch ex As Exception
lblError.Text = ex.Message
End Try
End Sub
那个小小的 try-except 块在很多(可能有十几个)地方重复出现。
有没有办法定义一个页面范围的“默认”异常处理程序,以便我可以这样说?
Private Overrides Sub DefaultHanderIWishIHad(ex As Exception)
lblError.Text = ex.Message
End Sub
Private Sub btnNextEvent_Click(sender As Object, e As EventArgs) Handles btnNextEvent.Click
'no need to handle here, because the default handler is just fine...
NextRegistration()
End Sub