473,763 Members | 1,543 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ThreadAbortExce ption - Why is it rethrown?

Hi,

I have a question regarding ThreadAbortExce ption. Why is the thread abort
exception rethrown at the end of a catch clause?
Why is ThreadAbortExce ption's behavior designed to be this way?

Thanks in advance
-Vivek
Nov 17 '05 #1
4 2905
Hi Vivek,

MSDN reads: "ThreadAbortExc eption is a special exception that can be caught,
but it will automatically be raised again at the end of the catch block."

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"Vivek" <Vi***@discussi ons.microsoft.c om> wrote in message
news:02******** *************** ***********@mic rosoft.com...
Hi,

I have a question regarding ThreadAbortExce ption. Why is the thread abort
exception rethrown at the end of a catch clause?
Why is ThreadAbortExce ption's behavior designed to be this way?

Thanks in advance
-Vivek


Nov 17 '05 #2
Vivek <Vi***@discussi ons.microsoft.c om> wrote:
I have a question regarding ThreadAbortExce ption. Why is the thread abort
exception rethrown at the end of a catch clause?
So that the thread will be actually *be* aborted unless it explicitly
says that it shouldn't be. There's plenty of code which catches all
exceptions but doesn't really want to stop a thread from being aborted.
Why is ThreadAbortExce ption's behavior designed to be this way?


Because otherwise Thread.Abort would be even more useless than it
already is.
(See http://www.pobox.com/~skeet/csharp/threads/abort.shtml for my
views on it.)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #3
Thanks for your views.
Now that i think more about it I wonder if it has anything to do with giving
functions upper in the call stack a chance to free unmanaged resourecs on
their call stack if any!
Example
foo1 is a method that the thread is executing (basically foo1 is the
ThreadStart parameter)
foo1 calls foo2 . foo2 opens some files (unmanaged calls) and then calls foo3
Assume we call the Abort method while foo3 is executing
If execution concluded in the ThreadAbortExce ption of foo3 the files would
still be open!

Maybe that's the reason by ThreadAbortExce ption is always rethrown unless
ResetAbort is explicitly called?

Any thoughts?
"Jon Skeet [C# MVP]" wrote:
Vivek <Vi***@discussi ons.microsoft.c om> wrote:
I have a question regarding ThreadAbortExce ption. Why is the thread abort
exception rethrown at the end of a catch clause?


So that the thread will be actually *be* aborted unless it explicitly
says that it shouldn't be. There's plenty of code which catches all
exceptions but doesn't really want to stop a thread from being aborted.
Why is ThreadAbortExce ption's behavior designed to be this way?


Because otherwise Thread.Abort would be even more useless than it
already is.
(See http://www.pobox.com/~skeet/csharp/threads/abort.shtml for my
views on it.)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #4
Vivek <Vi***@discussi ons.microsoft.c om> wrote:
Thanks for your views.
Now that i think more about it I wonder if it has anything to do with giving
functions upper in the call stack a chance to free unmanaged resourecs on
their call stack if any!
Sort of.
Example
foo1 is a method that the thread is executing (basically foo1 is the
ThreadStart parameter)
foo1 calls foo2 . foo2 opens some files (unmanaged calls) and then calls foo3
Assume we call the Abort method while foo3 is executing
If execution concluded in the ThreadAbortExce ption of foo3 the files would
still be open!


Execution couldn't end there - the stack will have to be unwound, and
that's why the exception is rethrown. If just catching
ThreadAbortExce ption stopped it from being rethrown, the thread
wouldn't be aborted at all. It's not that execution would stop there -
it would continue just like with any other exception.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2631
by: Anushya | last post by:
Hi When i abort a thread i get threadabort exception and wot all the things that need to be done there? IS releasing all the objects that are created is necesssary before aborting?Or aborting alone is sufficient? Join ing the thread till it is killed is impossible in my scenario as the exception is routed to some other layer. In the layer where abort is done, the user will not handle it.. THanks
6
2145
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, and altered flat-files produced. The job aborts at EXACTLY 105 seconds (1 min, 45 seconds) regardless of WHERE in the process we are - could be DB read, DB write, string manipulation - whatever.
3
1908
by: Steve - DND | last post by:
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...
4
1737
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. Despite being caught, this exception propagates all the way up the call stack. I know this is by design and that I can use Thread.ResetAbort to stop this exception from bubbling up the stack. But I want to know why the exception is thrown in the...
1
2400
by: Eric | last post by:
I have the following situation: I was getting intermittent errors using Reponse.Redirct("url", true) and was trying to catch the ThreadAbortException, but it was not staying caught and was showing up again where my code wasnt expecting it. I'm not sure what was causing it. The catch block in RedirectPage is supposed to quash the ThreadAbortException but it not only shows up there, but also in the outer catch block will catch it as well....
1
1588
by: Burak Gunay | last post by:
Hello, I have a piece of code where I am writing the contents of a datagrid to an excel report Dim tw As New StringWriter() Dim hw As New System.Web.UI.HtmlTextWriter(tw) Dim frm As HtmlForm = New HtmlForm() Response.ContentType = "application/vnd.ms-excel" Response.AddHeader("content-disposition",
6
7450
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. The question is: after the ThreadAbortException is thrown, does the childThread continue run the remaining code in the catch block?
3
3349
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, but there even when I get this fixed, there may be others I have not thought of. My immediate problem is that the web service seems to throw a threadabortexception to the client when it has an uncaught exception (I may be wrong. I am a bit confused...
0
1638
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 namespace mySite.Web <httpHandlers> <add verb="*" path="App/*.ashx" type="mySite.Web.AppHandler, App_Code"/>
0
9563
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10140
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9992
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9819
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8821
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7364
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5268
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3519
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.