locked
An unhandled exception has occurred RRS feed

  • Question

  • User-749395505 posted

    Dear Friend

    When we upload my compiled asp.net code on asp.net 4.0 server, then brouser show service unavailable and iis log file shows.

    Event Type:     Warning

    Event Source:    ASP.NET 4.0.30319.0

    Event
    Category:               
    Web Event

    Event
    ID:             
    1309

    Date:                    
    9/23/2011

    Time:                    
    1:16:54 AM

    User:                    
    N/A

    Computer:         
    WINBOX

    Description:

    Event code: 3005

    Event message: An unhandled exception has occurred.

    Event time: 9/23/2011 1:16:54 AM

    Event time (UTC): 9/23/2011 8:16:54 AM

    Event ID: da8b6f81c0614bf4b5926fd554f8cd79

    Event sequence: 4

    Event occurrence: 1

    Event detail code: 0

    How can we solve this problem.

    Friday, September 23, 2011 6:49 AM

Answers

  • User915387828 posted

    You should wrap your code in a Try...Catch block and display the exception, eg,

    public void SomeMethod()
    {

    try
    {
    ....your code goes here
    }
    catch (Exception ex)
    {
    ...do something to display ex.MessageText
    ...if not displaying it, then write to a file
    ...it can be as simple as response.write()

    }

    }

    More generally speaking, the rule of thumb for handling exceptions is that, unless you anticipate an error and plan on actually handling it, let it bubble up to the top most level of your application & handle it there. You can trap all "uncaught" exceptions in 3 ways:


    In the Application_Error of global.asax. All uncaught asp.net excpetions bubble up to this level, and this is my personal favorite. Here is a VB example of how to do this:
    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
    ' Get the exception at bottom of stack, the one that caused the problem
    Dim ex As Exception = Server.GetLastError.InnerException
    If ex Is Nothing Then
    ex = Server.GetLastError
    End If

    'You must do a ClearError
    Server.ClearError()
    'LoggingManger is my custom logging manager, wrap in a try...catch in case it fails!
    Try
    LoggingManager.WriteException(LOGGER_SRC_SYS, "", "", ex, "URL THAT CAUSED PROBLEM: " & Request.Url.PathAndQuery)
    Catch exc As Exception
    Dim evl As New EventLog
    EventLog.WriteEntry("WireTransfer", "LoggingManager has thrown an exception! " & _
    "See next entry for the exception that it was trying to write. " & _
    "LoggingManager exception is: " & exc.ToString)
    EventLog.WriteEntry("WireTransfer", "Error occured in Wire Transfer Status/Approval system: " & ex.ToString)
    Finally
    Server.Transfer("ErrorDisplayPage.aspx")
    End Try
    End Sub


    2. In web.config's customErrors section. Errors not caught in global.asax get handled here, but with less flexibility.

    <customErrors defaultRedirect="url" mode="On|Off|RemoteOnly">
    <error statusCode="statuscode" redirect="url"/>
    </customErrors>

    See the link I give below for more info about this -- you need more details to make this usable.

    3. In the page's Page_Error function. I consider this to be the least desirable way since it has to be on each page.

    See http://www.15seconds.com/issue/030102.htm for a detailed description of both methods, including a lot more detail about how to use web.config.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 28, 2011 3:46 AM

All replies

  • User1459534743 posted

    Can you share the code that causes the error. Also, have you setup the virtual directory for the web app?

    Friday, September 23, 2011 6:56 AM
  • User915387828 posted

    You should wrap your code in a Try...Catch block and display the exception, eg,

    public void SomeMethod()
    {

    try
    {
    ....your code goes here
    }
    catch (Exception ex)
    {
    ...do something to display ex.MessageText
    ...if not displaying it, then write to a file
    ...it can be as simple as response.write()

    }

    }

    More generally speaking, the rule of thumb for handling exceptions is that, unless you anticipate an error and plan on actually handling it, let it bubble up to the top most level of your application & handle it there. You can trap all "uncaught" exceptions in 3 ways:


    In the Application_Error of global.asax. All uncaught asp.net excpetions bubble up to this level, and this is my personal favorite. Here is a VB example of how to do this:
    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
    ' Get the exception at bottom of stack, the one that caused the problem
    Dim ex As Exception = Server.GetLastError.InnerException
    If ex Is Nothing Then
    ex = Server.GetLastError
    End If

    'You must do a ClearError
    Server.ClearError()
    'LoggingManger is my custom logging manager, wrap in a try...catch in case it fails!
    Try
    LoggingManager.WriteException(LOGGER_SRC_SYS, "", "", ex, "URL THAT CAUSED PROBLEM: " & Request.Url.PathAndQuery)
    Catch exc As Exception
    Dim evl As New EventLog
    EventLog.WriteEntry("WireTransfer", "LoggingManager has thrown an exception! " & _
    "See next entry for the exception that it was trying to write. " & _
    "LoggingManager exception is: " & exc.ToString)
    EventLog.WriteEntry("WireTransfer", "Error occured in Wire Transfer Status/Approval system: " & ex.ToString)
    Finally
    Server.Transfer("ErrorDisplayPage.aspx")
    End Try
    End Sub


    2. In web.config's customErrors section. Errors not caught in global.asax get handled here, but with less flexibility.

    <customErrors defaultRedirect="url" mode="On|Off|RemoteOnly">
    <error statusCode="statuscode" redirect="url"/>
    </customErrors>

    See the link I give below for more info about this -- you need more details to make this usable.

    3. In the page's Page_Error function. I consider this to be the least desirable way since it has to be on each page.

    See http://www.15seconds.com/issue/030102.htm for a detailed description of both methods, including a lot more detail about how to use web.config.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 28, 2011 3:46 AM
  • User-448512826 posted

    Hi,

    check also..

    http://support.microsoft.com/kb/842493

    Thanks...

    Wednesday, September 28, 2011 4:51 AM