Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs
' Get the exception object.
Dim exc As Exception = Server.GetLastError
' Handle HTTP errors (avoid trapping HttpUnhandledException
' which is generated when a non-HTTP exception
' such as the ones generated by buttons 1-3 in
' Default.aspx is not handled at the page level).
If (exc.GetType Is GetType(HttpException)) Then
' The Complete Error Handling Example generates
' some errors using URLs with "NoCatch" in them;
' ignore these here to simulate what would happen
' if a global.asax handler were not implemented.
If exc.Message.Contains("NoCatch") Then
Return
End If
'Redirect HTTP errors to HttpError page
Server.Transfer("HttpErrorPage.aspx")
End If
' For other kinds of errors give the user some information
' but stay on the default page
Response.Write("<h2>Global Page Error</h2>" & vbLf)
Response.Write("<p>" & exc.Message + "</p>" & vbLf)
Response.Write(("Return to the <a href='Default.aspx'>" _
& "Default Page</a>" & vbLf))
' Log the exception and notify system operators
ExceptionUtility.LogException(exc, "DefaultPage")
ExceptionUtility.NotifySystemOps(exc)
' Clear the error from the server
Server.ClearError()
End Sub