Error handling in ASP.NET

samsmithnz

Senior Contributor
Joined
Jul 22, 2003
Messages
1,038
Location
Boston
This is driving me up the wall. I just can't get a generic errorhandler to work. I've tryed every method. This is probably the easiest one for me.

Every function I have has an errorhandler like this:
Code:
        Catch ex As Exception
            Throw ex
        End Try

Then in the Global.asax file I have:
Code:
    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        Response.Redirect("Error.aspx", False)
    End Sub

Then in my Error.aspx file I have:
Code:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lblError.Text = Server.GetLastError.ToString
    End Sub

BUT it doesn't work, one of two things happens...
1. The error occurs on the page that it occurs and writes the standard vs.net error message out the screen.
2. The error handler actually manages to redirect to the error.aspx file, but I get a Object not initalised error while checking for the last error (Server.GetLastError = Nothing).

Why won't this work for me :( :(
 
Once you redirect to the error page, the server.getlasterror is gone. I've never got it to work. Recalling from our past thread, try storing the exception into the application object, then grab it from your error page.
 
Back
Top