470,586 Members | 1,313 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,586 developers. It's quick & easy.

ThreadAbortException not behaving properly?

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
Nov 18 '05 #1
3 1736
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:Oy**************@TK2MSFTNGP12.phx.gbl...
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

Nov 18 '05 #2
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]" <sa******@sct.co.in.nospam> wrote in message
news:ul*************@TK2MSFTNGP11.phx.gbl...
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

Nov 18 '05 #3
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:eh*************@TK2MSFTNGP10.phx.gbl...
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]" <sa******@sct.co.in.nospam> wrote in message
news:ul*************@TK2MSFTNGP11.phx.gbl...
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


Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Mark Phillips | last post: by
6 posts views Thread by David Waz... | last post: by
3 posts views Thread by =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post: by
reply views Thread by Zeba | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.