So I handle all exceptions in my project within my Global.asax page. For example, on a random page I could have:
Protected Sub SomeFunction()
Try
'do something here
Catch ex As Exception
Throw ex
End Try
End Sub
So then the exception bubbles up to the Global.asax page where I handle it and log to the database like so:
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim ex As Exception = Server.GetLastError
Dim loggedExceptionID As Integer = 0
Try
loggedExceptionID = New BLL.ExceptionHandler().LogException(ex)
Response.Redirect("~/ErrorPage.aspx?ID=" & loggedExceptionID, False)
Catch loggingError As Exception
'what do I do here?
End Try
End Sub
The BLL.ExceptionHandler().LogException(ex) function just writes the error details to the database.
So my question is in the Application_Error method, do I need the try/catch block when trying to write to the database? I'm thinking I would in case something goes wrong with the connection, etc. - but is this really necessary? Also, what would I do in the catch block if there is an error? At that point I would be catching the error of logging an error which is confusing in its own right.