473,382 Members | 1,615 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,382 software developers and data experts.

ThreadAbortException - Why is it rethrown?

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?

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

MSDN reads: "ThreadAbortException 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***@discussions.microsoft.com> wrote in message
news:02**********************************@microsof t.com...
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?

Thanks in advance
-Vivek


Nov 17 '05 #2
Vivek <Vi***@discussions.microsoft.com> wrote:
I have a question regarding ThreadAbortException. 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 ThreadAbortException'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.com>
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 ThreadAbortException of foo3 the files would
still be open!

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

Any thoughts?
"Jon Skeet [C# MVP]" wrote:
Vivek <Vi***@discussions.microsoft.com> wrote:
I have a question regarding ThreadAbortException. 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 ThreadAbortException'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.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #4
Vivek <Vi***@discussions.microsoft.com> 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 ThreadAbortException 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
ThreadAbortException 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.com>
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
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...
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,...
3
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...
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....
1
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...
1
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...
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.