GetLastError - It doesnt work :(

Extremebfn
04-19-2007, 12:21 AM
Hi Guys.. I want to use my own CustomError page to inform my users of errors on the page. Im am doing the following:

I have the following in my web.config:

<customErrors mode="On" defaultRedirect="mcerror.aspx" />

That enables customErrors on my web-application.

Now when a error occurs, it automaticly redirects the page to mcerror.aspx.

On in Page_Load event on mcerror.aspx i have the following code:


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ex As Exception = Server.GetLastError

lblError.text = ex.Message.ToString

End Sub


Now acording to MSDN, the GetLastError method returns the last Exception. So i want to use the GetLastError method to show the error that was generated and then print that inside the Label(lblError), but it doesnt seem to work, i get the following error:


Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Might it be that GetLastError doesnt have a value? If so, how can i get the current error and display that, and not the previous error, because a current error might exsist, but a previous error might not?

Please any help would be appreciated.

Regards

MKoslof
04-19-2007, 11:54 AM
Are you calling Server.ClearError() at any point in time? Are handling anything at the global level or within the Application_Error event?

If you step through the code is ex null? If it's not, then the actual top level message property is null.

If ex is NOT null try ex.InnerException. But I suspect when you get to the form, the Server has already handled the error.

Can you walk us through exactly what you have done? Have you only set this value in your Web.Config, nothing more?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum