locked
Throwing exceptions in Application_Error RRS feed

  • Question

  • User1610993789 posted

    Hi,

     I have some code within the application error event in global.asax. This codes does a number of things like logging and emailing but when debug mode is ON, i'd like for it to skip all that and just proceed to the normal Exception HTML "Server Error" page.

     Checking whether debug mode is on or off is not the issue here, the issue is that if i just put a "throw exception" line there then sometimes it just goes back to Application_Error and creates an infinite loop.

    How can i do this?

    Thursday, May 10, 2007 4:50 AM

Answers

  • User-2115483147 posted

    Hi ,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>

    See this demo as follows:<o:p></o:p>

    http://www.codeproject.com/aspnet/ErrorHandlingASPNET.asp<o:p></o:p>

    <o:p> </o:p>

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.<o:p></o:p>

    Hope it helps,<o:p></o:p>

    Hong Gang<o:p></o:p>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 15, 2007 10:24 PM

All replies

  • User-1714679672 posted

    Global.asax
        Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
            Session("exp") = HttpContext.Current.Server.GetLastError().GetBaseException()
        End Sub

    Web.config
    <customErrors mode="On" defaultRedirect="Error.aspx" />

    Error Page
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    #If DEBUG Then
            Dim _Error As Exception = Session("exp")

    #Else
            Dim _Error As Exception = Session("exp")
    #End If
        End Sub

     

     

    HTH

    Thursday, May 10, 2007 5:36 AM
  • User1610993789 posted
    I know how to achive this by creating a separate page, what i'm looking for is a simpler way to just throw the error without application_error catching it or something similar. Is this possible?
    Thursday, May 10, 2007 7:20 AM
  • User-2115483147 posted

    Hi ,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>

    See this demo as follows:<o:p></o:p>

    http://www.codeproject.com/aspnet/ErrorHandlingASPNET.asp<o:p></o:p>

    <o:p> </o:p>

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.<o:p></o:p>

    Hope it helps,<o:p></o:p>

    Hong Gang<o:p></o:p>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 15, 2007 10:24 PM