I get the Exception "Thread is being aborted"
-
Hi, I am beginner in asp.net and my problem When i try to redirect with the code Response.Redirect("~/Zone/Home.aspx?ZID=24&"); an exception is being raised i.e; "Thread is being aborted" and after this redirection is done without any problems. What cud be the possible mistake made by me? Plz help.
-
Hi, I am beginner in asp.net and my problem When i try to redirect with the code Response.Redirect("~/Zone/Home.aspx?ZID=24&"); an exception is being raised i.e; "Thread is being aborted" and after this redirection is done without any problems. What cud be the possible mistake made by me? Plz help.
-
If you look at the Redirect[^] documentation, you will see it takes a second parameter of a type of bool to indicate if you want to terminate current page execution use instead
Response.Redirect("~/Zone/Home.aspx?ZID=24&", false);
Yusuf May I help you?
Thanx a lot
-
Thanx a lot
But, be aware that if you do set the value to false, the page you are currently on will continue to process. If the value is true (the default) then the page stops processing immediately. See also the answer I gave here[^]
Man who stand on hill with mouth open wait long time for roast duck to drop in
-
But, be aware that if you do set the value to false, the page you are currently on will continue to process. If the value is true (the default) then the page stops processing immediately. See also the answer I gave here[^]
Man who stand on hill with mouth open wait long time for roast duck to drop in
Colin Angus Mackay wrote:
See also the answer I gave here[^] try{ // My code that does a redirect}catch(ThreadAbortException){ throw; // Continue throwing the ThreadAbortException}catch(Exception ex){ // Catch any other type of exception and handle the error.}
That is interesting, but I am not sure how it will work though. In my code I use expensively try/catch. Then I have have catch all basin at the application level. Any unhandled exception will end up at the catch basin. If you rethrow the
ThreadAbortException
doesn't it get bubbled up. Don't you want to eat that exception?Yusuf May I help you?
-
Colin Angus Mackay wrote:
See also the answer I gave here[^] try{ // My code that does a redirect}catch(ThreadAbortException){ throw; // Continue throwing the ThreadAbortException}catch(Exception ex){ // Catch any other type of exception and handle the error.}
That is interesting, but I am not sure how it will work though. In my code I use expensively try/catch. Then I have have catch all basin at the application level. Any unhandled exception will end up at the catch basin. If you rethrow the
ThreadAbortException
doesn't it get bubbled up. Don't you want to eat that exception?Yusuf May I help you?
Yusuf wrote:
If you rethrow the ThreadAbortException doesn't it get bubbled up.
Yes, it will.
Yusuf wrote:
Don't you want to eat that exception?
Nope. It is the exception that the Redirect method throws to force the end of execution. If you catch it and eat it execution resumes when you've already said you want it to stop so you can redirect elsewhere. (Although, I've been told that ASP.NET will automatically rethrow it if you catch it - which I didn't know before and wish to confirm before I change my stance as I don't see how it does it.)
Man who stand on hill with mouth open wait long time for roast duck to drop in