Do something on an uncaught exception.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob

    #1

    Do something on an uncaught exception.

    Hi all,

    I have a small helper service that is peppered with try-catches for all the
    exceptional cases I could think of.
    It industriously logs every error it comes across for debugging later on.

    Wonderful; however on the odd time it blows a gasket the solution is in
    99.9% the same .. restart the service.
    Then go away and track down the source of the bug fix-test-deploy.
    usually a 5 min fix .. but often a call at 3am ...

    Is there a mechanism for catching these "uncaught" exceptions in the
    application so that I could then launch another instance of the service and
    gracefully close down the 'afflicted' app.

    regards Bob

    p.s. .. I'm sure explorer.exe does this .. it seems to hang and restart all
    the time.


  • Michael C

    #2
    Re: Do something on an uncaught exception.

    "Bob" <nospamSam@nosp amSam.com.auwro te in message
    news:e9AT$$X2HH A.5380@TK2MSFTN GP04.phx.gbl...
    Hi all,
    >
    I have a small helper service that is peppered with try-catches for all
    the exceptional cases I could think of.
    It industriously logs every error it comes across for debugging later on.
    >
    Wonderful; however on the odd time it blows a gasket the solution is in
    99.9% the same .. restart the service.
    Then go away and track down the source of the bug fix-test-deploy.
    usually a 5 min fix .. but often a call at 3am ...
    >
    Is there a mechanism for catching these "uncaught" exceptions in the
    application so that I could then launch another instance of the service
    and gracefully close down the 'afflicted' app.
    Application.Thr eadException += new blah....

    I'm not sure if you need to do this for each thread you create so it would
    be worth testing here. With a service though don't you have a single point
    that calls all code so can trap everything there? This is what I have and
    don't need to restart the service.

    Michael


    Comment

    • AlanT

      #3
      Re: Do something on an uncaught exception.

      >>Is there a mechanism for catching these "uncaught" exceptions in the
      >>application so that I could then launch another instance of the service and
      >>gracefully close down the 'afflicted' app.
      >Application.Th readException += new blah....
      If that does not catch everything you might also try the

      AppDomain.Curre ntDomain.Unhand ledException += ....


      hth,
      Alan.

      Comment

      • ron willoughby

        #4
        Error Recovery

        I am assuming that you are in .net. If so then above the page level which you seem to be catching there are the application level of global.aspx and also the last level below the server of web.config. Both have error traps that you can use. However, there are some errors that are a the server level that never get to the application and those are handled by the server. Look at Application_Err or in global.aspx; and customerrors in the web.config.

        EggHeadCafe.com - .NET Developer Portal of Choice

        Comment

        • Bob

          #5
          Re: Do something on an uncaught exception.

          Thanks for this .. I'll give it a shot ...

          regards Bob


          Comment

          • Mike Blake-Knox

            #6
            Re: Do something on an uncaught exception.

            In article <e2El0ZT3HHA.51 16@TK2MSFTNGP04 .phx.gbl>, Michael C wrote:
            In a service most code will start from a single point which will probably beĀ 
            a timer, so it's easy to catch any exception there.
            Except for thread pool threads and asynchronous callback threads. For instance,
            an exception thrown in a handler for completion of a socket receive needs to be
            handled in a try/catch handler (or by the handler for
            AppDomain.Curre ntDomain.Unhand ledException) as Allan suggested.

            Mike

            Comment

            • Michael C

              #7
              Re: Do something on an uncaught exception.

              "Mike Blake-Knox" <mikebk@communi ty.nospamwrote in message
              news:VA.000000b 5.107f764c@comm unity.nospam...
              Except for thread pool threads and asynchronous callback threads. For
              instance,
              an exception thrown in a handler for completion of a socket receive needs
              to be
              handled in a try/catch handler (or by the handler for
              AppDomain.Curre ntDomain.Unhand ledException) as Allan suggested.
              Excellent suggestion. This could be a problem in my service, I noticed some
              exceptions not getting handled when I was developing even though I thought
              everything should be caught. I think I probably eliminated them just by
              fixing whatever was causing the exception but it would definately be worth
              me revisiting it. Thanks for the tip.

              Michael


              Comment

              Working...