Catching exceptions inside static callback methods

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

    Catching exceptions inside static callback methods

    If I catch an exception in a static callback method like:

    private static void ResponseCallbac k(IAsnycResult
    asyncResult)
    {
    try { //code...code...c ode }
    catch (WebException e)
    { //handle exception }
    }

    will that that WebException object remain for the life of
    the process???

    I have a windows service which makes WebRequests and uses
    a callback to handle asynchronous requests, but if
    there's an exception raised, I want to be able to
    continue using this class later on. I've had a hard time
    debugging it, but it seems like once there's an exception
    raised, I keep catching an exception, even when I'm
    pretty sure the request should succeed.

    Does the WebException remain in memory the same as other
    static members??? If so how, should this kind of
    situation be coded?

    Thanks

  • Greg Ewing [MVP]

    #2
    Re: Catching exceptions inside static callback methods

    Adam, no, that web exception will not always be in memory. It sounds like
    there is something else going on with the methods which you think should be
    successful. How are you doing your debugging? If you are still seing a
    problem please post a complete, runnable sample that demonstrates the
    problem.

    --
    Greg Ewing [MVP]



    "Adam" <adam.burns@exc ell.com> wrote in message
    news:0ec801c38d 15$41642e60$a00 1280a@phx.gbl.. .[color=blue]
    > If I catch an exception in a static callback method like:
    >
    > private static void ResponseCallbac k(IAsnycResult
    > asyncResult)
    > {
    > try { //code...code...c ode }
    > catch (WebException e)
    > { //handle exception }
    > }
    >
    > will that that WebException object remain for the life of
    > the process???
    >
    > I have a windows service which makes WebRequests and uses
    > a callback to handle asynchronous requests, but if
    > there's an exception raised, I want to be able to
    > continue using this class later on. I've had a hard time
    > debugging it, but it seems like once there's an exception
    > raised, I keep catching an exception, even when I'm
    > pretty sure the request should succeed.
    >
    > Does the WebException remain in memory the same as other
    > static members??? If so how, should this kind of
    > situation be coded?
    >
    > Thanks
    >[/color]


    Comment

    • Adam

      #3
      Re: Catching exceptions inside static callback methods

      Thanks Greg,

      That's what I thought. Debugging is only a problem
      because the problem occurs so rarely and I've been too
      busy to set up a workable test bed to reproduce the
      problem. I'd have to have a web site that returns a 401
      access denied error, recompile etc, etc.

      Posting a working version might be tricky, since I'd need
      to post several classes. It's a service, but if (more
      likely when) I get to that point, I'll create a paired
      down version of the program. Then if I still can't
      figure it out, I'll repost. Thanks again.
      [color=blue]
      >-----Original Message-----
      >Adam, no, that web exception will not always be in[/color]
      memory. It sounds like[color=blue]
      >there is something else going on with the methods which[/color]
      you think should be[color=blue]
      >successful. How are you doing your debugging? If you[/color]
      are still seing a[color=blue]
      >problem please post a complete, runnable sample that[/color]
      demonstrates the[color=blue]
      >problem.
      >
      >--
      >Greg Ewing [MVP]
      >http://www.claritycon.com/
      >
      >
      >"Adam" <adam.burns@exc ell.com> wrote in message
      >news:0ec801c38 d15$41642e60$a0 01280a@phx.gbl. ..[color=green]
      >> If I catch an exception in a static callback method[/color][/color]
      like:[color=blue][color=green]
      >>
      >> private static void ResponseCallbac k(IAsnycResult
      >> asyncResult)
      >> {
      >> try { //code...code...c ode }
      >> catch (WebException e)
      >> { //handle exception }
      >> }
      >>
      >> will that that WebException object remain for the life[/color][/color]
      of[color=blue][color=green]
      >> the process???
      >>
      >> I have a windows service which makes WebRequests and[/color][/color]
      uses[color=blue][color=green]
      >> a callback to handle asynchronous requests, but if
      >> there's an exception raised, I want to be able to
      >> continue using this class later on. I've had a hard[/color][/color]
      time[color=blue][color=green]
      >> debugging it, but it seems like once there's an[/color][/color]
      exception[color=blue][color=green]
      >> raised, I keep catching an exception, even when I'm
      >> pretty sure the request should succeed.
      >>
      >> Does the WebException remain in memory the same as[/color][/color]
      other[color=blue][color=green]
      >> static members??? If so how, should this kind of
      >> situation be coded?
      >>
      >> Thanks
      >>[/color]
      >
      >
      >.
      >[/color]

      Comment

      Working...