473,406 Members | 2,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 1885
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: amit kumar | last post by:
I am calling a function which returns pointer to a map. The declaration of the map is map<int,vectxyz*>. vectxyz is a vector containing pointer to a class xyz. For map<int,vectxyz*>* p1 In the...
4
by: Stephan Steiner | last post by:
Hi I'm having some weird threading issues.. almost at random, if I dare change a line of my code, the shutdown sequence gets messed up. I'm using a thread to receive data from the network, that...
0
by: Mark Phillips | last post by:
Hello, I am having a problem in which a file can get stuck open when a thread that is attempting to write to it gets aborted (ThreadAbortedException occurs). The log file gets stuck open until...
4
by: Vivek | last post by:
Hi, I have a question regarding ThreadAbortException. Why is the thread abort exception rethrown at the end of a catch clause? Why is ThreadAbortException's behavior designed to be this way? ...
6
by: David Waz... | last post by:
Moved an app from W/2000 Asp V1.0 to W/2003, VS/2003, ASPV 1.1 Page runs a long job, uploading 2 large fixed length files (300,000 rows) into SQL database. A process is run against the data,...
4
by: splap20 | last post by:
Every day a large chunk of XML is posted up to my app via http. The app interprets this XML and writes results to a SQLServer. Occasionally a ThreadAbortException is thrown during this process....
6
by: foolmelon | last post by:
If a childThread is in the middle of a catch block and handling an exception caught, the main thread calls childThread.Abort(). At that time a ThreadAbortException is thrown in the childThread. ...
3
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
Hi, I am running a web service which sometimes throws exceptions. I have a lot of error trapping within the web service, but I have missed the current problem. I am working on the current issue,...
0
by: Zeba | last post by:
Hi ! I am using a httphandler to perform some url rewriting in my application. My web.config contains the following entry to direct all urls containing /App/*.ashx to my class AppHandler.cs in...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.