2

I know all about this exception, read the msdn article here http://support.microsoft.com/kb/312629/EN-US/ but I do not know how to handle this when my boss does not want me to throw in false for the Response.End.

Here's what I have:

        else 
        {
 try
 {
  VoidlOrder(transactionID);
 }
 catch (Exception ex)
 {
  LogError(ex.ToString());
 }
 finally
 {
     RedirectUser(sessionID,"showfmsg=1", true);
 }
        }

RedirectUser is just a utility method we run that ultimately passes in true for the reponse.redirect resopnse.end param.

So what other option is there other than putting false as this param? He's stating to catch it and do something...ok do what? I don't see any other fix than to send false into this call every time because I can't get pass this exception..I get it every time.

UPDATED

tried this but I still get a threadabortexception in the outer catch:

          else 
        {
                try
                {

                    VoidOrder(transactionID);
                }
                catch (Exception ex)
                {
                    LogError(ex.ToString());
                }
                finally
                {
                    try
                    {
                    RedirectUserBackToCheckout(sessionID, "showfmsg=1", true);
                    }
                    catch (ThreadAbortException)
                    {

                    }

                }
        }
    }
    catch (Exception ex)
    {
        // some other logic
    }
PositiveGuy
  • 46,620
  • 110
  • 305
  • 471
  • If he literally told you to do something, then I would literally go back to him and ask him what he meant. If that isn't the posterchild for an incomplete spec, I don't know what is. If he told you to do something specific, what did he tell you to do? Are you doing it? – Lasse V. Karlsen Apr 26 '10 at 21:44
  • No clue how he wants to handle this. He said just to catch the threadaboard and handle it somehow...yea, it's not much help in terms of direction. – PositiveGuy Apr 26 '10 at 21:46
  • 1
    Why do you need to handle it? The exception is thrown in response to a redirect or end call, it is thrown in order to unwind the stacks and execute all finally-blocks before terminating the request. What kind of handling do you expect to do? And if you don't know, nobody here will either. – Lasse V. Karlsen Apr 26 '10 at 21:48
  • Ok, got back with him. He's saying to ignore it in the catch or throw a false but better to just igngore it and return rather than do the Thead.ResetAbort because ResetAbort is kind a weird way to reset it to false. – PositiveGuy Apr 26 '10 at 21:54
  • Lassee I have no clue how to handle it. That's why I'm posting this here. Looks like you don't handle it at all other than you can log it but that is about it. Just try/catch and if you catch this exception just ignore it in the catch by doing nothing. – PositiveGuy Apr 26 '10 at 21:55
  • Lassee I figured someone had some techniques or ways or maybe nothing (do nothing and ignore it) but wasn't sure since I've never had to handle this type of exception before. – PositiveGuy Apr 26 '10 at 21:55
  • I mean everyone's prob come across this and I was just curious what people have done when catching it other than doing another Response.Redirect with false. – PositiveGuy Apr 26 '10 at 21:56
  • So add a catch-block like what SLaks posted in his answer, just leave out the resetabort call, and you should be set, this will catch, but ignore, the exception. – Lasse V. Karlsen Apr 26 '10 at 22:00
  • Ok, I just put nothing in the catch. And I still get the threadabort error. Looks like ignoring it does not work. See updated post. – PositiveGuy Apr 26 '10 at 22:06
  • You **are** looking for `Thread.ResetAbort();` – SLaks Apr 26 '10 at 22:15
  • I am not looking for ResetAbort according to my boss. lol – PositiveGuy Apr 26 '10 at 22:17
  • check this out. I have mine in a finally: http://stackoverflow.com/questions/2251964/c-thread-termination-and-thread-abort – PositiveGuy Apr 26 '10 at 22:38
  • and this http://stackoverflow.com/questions/1559255/whats-wrong-with-using-thread-abort/1560567#1560567 which are all saying this TheadAbort can break your application. – PositiveGuy Apr 26 '10 at 22:39
  • 1
    In controlled circumstances (which this is), there is nothing wrong with `ResetAbort`. – SLaks Apr 27 '10 at 01:17

1 Answers1

2

Your question doesn't make sense, but you're probably looking for

catch(ThreadAbortException) { Thread.ResetAbort(); }

EDIT: You need to call Thread.ResetAbort(); in your catch block.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • I don't want to just check for ThreadAbortExcetions. Putting it in my catch like this would bypass any other type of exceptions. – PositiveGuy Apr 26 '10 at 21:43
  • Your question, there is none. What specifically are you asking about? How to avoid the exception? How to handle it? – Lasse V. Karlsen Apr 26 '10 at 21:46
  • how to handle it other than throwing false into another Redirect after you catch that Exception. In this case I have my catch in a finally so I can't just return and ignore it. – PositiveGuy Apr 26 '10 at 22:04
  • what is not clear about this sentence "So what other option is there other than putting false as this param? He's stating to catch it and do something...ok do what? I don't see any other fix than to send false into this call every time because I can't get pass this exception..I get it every time." – PositiveGuy Apr 26 '10 at 22:04
  • I was asking clearly how to handle it other than doing another Response.Redirect with false. My boss says to just return from the catch and ignore it. Well you can't return from a finally statement. I want to know what others have done in this situation other than throwing false into the Response.End – PositiveGuy Apr 26 '10 at 22:05
  • lol, my boss doesn't want me to call Thread.ResetAbort...he says that's sort of a weird way to do this. he said just ignore the error or throw false. I guess he changed his mind about false...lol. Ignoring it would work except in this situation I don't want my final catch handling it. So I guess false is the only option here. – PositiveGuy Apr 26 '10 at 22:18
  • @coffeeaddict: Your boss is completely wrong. There is no other way to do it. – SLaks Apr 26 '10 at 22:27
  • his response was ok, but know that the page is still going to process on after the redirect. I know that... So actually catching the abort never worked and just rethrew the exception again! I took the try/catch out and just used false. We have thousands of users on our site. I think he's worried about too much processing going on if we do start to get these exceptions for whatever reason. He says he ignores any thread aborts at the top level (bubbles up) in our code but I just tried to ignore it like that and it doesn't work. It rethrows the abort for some reason to the final catch – PositiveGuy Apr 26 '10 at 22:35