Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you pass an exception to another page? 1

Status
Not open for further replies.

Glowworm27

Programmer
Joined
May 30, 2003
Messages
587
Location
US
I was wondering,

Can you pass an exception to another page? can you store the exception in a session variable?

I am trying to create a generic Error page that will inform the user that an error occured, Write the error to a logfile, and send an email , I also want it to display the error too. and allow them to continue working.

I have tryed to use the custom errors redirect method, but it looses session state, so I can't store the error in session variables, So iv'e decidecd to create my own error handling routine.



George Oakes
Goakes@TiresPlus.com = Programmer
George@1-Specialday.com = Mobile DJ
Check out this awsome .Net Resource!
 
WHat you can do is throw the error from your error handling routin and catch it in the Application_Error event in Global.asax.

I use the following code:

Code:
 Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when an error occurs
        Dim bex As New Microsoft.ApplicationBlocks.ExceptionManagement.BaseApplicationException(Server.GetLastError.Message, Server.GetLastError)
        bex.Source = "FormGen.Web.Global"
        Microsoft.ApplicationBlocks.ExceptionManagement.ExceptionManager.Publish(bex)
        Server.Transfer("error.aspx")
    End Sub

In the case of the Server.Transfer you can pass the error message via a querystring variable.

The applications block code relates to the exception management application block from MSDN. Its well worth downloading and implementing. You can write custom publishers to save the error data to and output medium. I write it to a SQL server database. The default is the eventlog. You can find the download and info at
Hope this helps,

james :-)

James Culshaw
james@miniaturereview.co.uk
 
Sub Application_Error

Does not go to the page when I put in the line

Server.Transfer("error.aspx")

instead it displays the error message
How do I get it to go to that page?


George Oakes
Goakes@TiresPlus.com = Programmer
George@1-Specialday.com = Mobile DJ
Check out this awsome .Net Resource!
 
Yeah I know that error.aspx is a page you created, My application does not even go to My error page that I created. Server.Transfer("Genericerror.aspx")

But I figured it out anyway. it seems that in my
Sub Application_Error routine there was an error about the SMTP server, so it never made it to the customer error page.
I have fixed the SMTP error I was getting and now it is operating fine.

Thanks for the help
:-)


George Oakes
Goakes@TiresPlus.com = Programmer
George@1-Specialday.com = Mobile DJ
Check out this awsome .Net Resource!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top