ThreadAbortException not behaving properly?

Discussion in 'ASP .Net' started by Steve - DND, May 19, 2004.

  1. Steve - DND

    Steve - DND Guest

    I just implemented a page that performs a Response.Redirect(url, true). As
    such, I wrapped it in a try catch, and explicitly caught a
    ThreadAbortException. However, the thread abort exception was still thrown
    at every catch block above the try/catches level, as well as at the *same*
    level as the try/catch. This does not seem like proper behavior at all. Once
    I've caught the exception, why is it still propagating up the stack? I could
    maybe understand it going up the stack, but how it it getting into catch
    blocks at the same level? Below is some code that illustrates what happened.

    function void doStuff(string url) {
    try {
    try {
    Response.Redirect(url, true);
    } catch (ThreadAbortException) {
    //This is hit
    Logger.Log("Aborted");
    }

    try {

    } catch (Exception e) {
    //This is hit.
    Logger.Log(e, "Aborted same level");
    }
    } catch (Exception e) {
    //This is hit.
    Logger.Log(e, "Aborted level above");
    }
    }

    All of those Log statements are hit unless for each one I put a "catch
    (ThreadAbortException)" in there. What is going on here, and why?

    Thanks,
    Steve
     
    Steve - DND, May 19, 2004
    #1
    1. Advertisements

  2. I dont know why it is behaving like this in your case. But you can avoid the
    threadabortexception by passing "false" as second parameter to
    response.redirect.

    --
    Saravana
    Microsoft MVP - ASP.NET
    www.extremeexperts.com



    "Steve - DND" <steve!@!digitalnothing.com> wrote in message
    news:...
    > I just implemented a page that performs a Response.Redirect(url, true). As
    > such, I wrapped it in a try catch, and explicitly caught a
    > ThreadAbortException. However, the thread abort exception was still thrown
    > at every catch block above the try/catches level, as well as at the *same*
    > level as the try/catch. This does not seem like proper behavior at all.

    Once
    > I've caught the exception, why is it still propagating up the stack? I

    could
    > maybe understand it going up the stack, but how it it getting into catch
    > blocks at the same level? Below is some code that illustrates what

    happened.
    >
    > function void doStuff(string url) {
    > try {
    > try {
    > Response.Redirect(url, true);
    > } catch (ThreadAbortException) {
    > //This is hit
    > Logger.Log("Aborted");
    > }
    >
    > try {
    >
    > } catch (Exception e) {
    > //This is hit.
    > Logger.Log(e, "Aborted same level");
    > }
    > } catch (Exception e) {
    > //This is hit.
    > Logger.Log(e, "Aborted level above");
    > }
    > }
    >
    > All of those Log statements are hit unless for each one I put a "catch
    > (ThreadAbortException)" in there. What is going on here, and why?
    >
    > Thanks,
    > Steve
    >
    >
     
    Saravana [MVP], May 19, 2004
    #2
    1. Advertisements

  3. Steve - DND

    Steve - DND Guest

    But then it will continue to process any code left on the page, won't it? So
    I would have to implement a class level variable indicating that no further
    processing should occur. Correct?

    Steve

    "Saravana [MVP]" <> wrote in message
    news:...
    > I dont know why it is behaving like this in your case. But you can avoid

    the
    > threadabortexception by passing "false" as second parameter to
    > response.redirect.
    >
    > --
    > Saravana
    > Microsoft MVP - ASP.NET
    > www.extremeexperts.com
     
    Steve - DND, May 19, 2004
    #3
  4. You are correct, it will process the code after response.redirect. If you
    dont want it to happen, then you shouldnt pass "false" as the parameter
    value for EndResponse parameter.

    --
    Saravana
    Microsoft MVP - ASP.NET
    www.extremeexperts.com



    "Steve - DND" <steve!@!digitalnothing.com> wrote in message
    news:...
    > But then it will continue to process any code left on the page, won't it?

    So
    > I would have to implement a class level variable indicating that no

    further
    > processing should occur. Correct?
    >
    > Steve
    >
    > "Saravana [MVP]" <> wrote in message
    > news:...
    > > I dont know why it is behaving like this in your case. But you can avoid

    > the
    > > threadabortexception by passing "false" as second parameter to
    > > response.redirect.
    > >
    > > --
    > > Saravana
    > > Microsoft MVP - ASP.NET
    > > www.extremeexperts.com

    >
    >
     
    Saravana [MVP], May 20, 2004
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric
    Replies:
    1
    Views:
    671
    =?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN
    Aug 19, 2005
  2. Ken Kafieh
    Replies:
    7
    Views:
    2,720
    Roedy Green
    May 19, 2004
  3. William Krick
    Replies:
    4
    Views:
    78,854
    rt19983
    Dec 18, 2008
  4. mark | r

    list not behaving

    mark | r, Sep 3, 2004, in forum: HTML
    Replies:
    2
    Views:
    391
  5. amit kumar
    Replies:
    5
    Views:
    6,293
    velthuijsen
    May 18, 2004
  6. DamonChong
    Replies:
    8
    Views:
    483
    Old Wolf
    Jan 30, 2005
  7. Skip Montanaro

    sys._getframe() not behaving as expected

    Skip Montanaro, Dec 1, 2003, in forum: Python
    Replies:
    0
    Views:
    464
    Skip Montanaro
    Dec 1, 2003
  8. SHC
    Replies:
    1
    Views:
    425
    Jonathan N. Little
    Sep 7, 2006
Loading...