Re: Thread Abort and Unhandled Exception Event
- From: pawel.kedzior@xxxxxxxxx
- Date: 18 Apr 2007 12:55:46 -0700
Hi Pete
I think you misunderstand the nature of "UnhandledException". It's anI might have called that a handler, but I never thought so. The key is
event, not an exception handler.
that once the application is terminating, you can not cancel the
process.
then you need to put an exception
handler in the thread itself (that is, try/catch at the top of the thread
*and* make sure that you never abort the thread unless you are 100%
certain that the thread is within the try block).
So what you suggest is to:
Thread th = new Thread(new ThreadStart(foo)); th.Start();
....
th.Abort();
....
public void foo() {
try {
...
} catch (Exception e)
{...}
}
I understand that you claim that the catch block will prevent from
slipping ThreadAbortException outside foo() if only Abort was called
within try/catch.
That is not actually true, because ThreadAbortException will be
rethrown automatically after leaving catch{} block, provided that
Thread.ResetAbort() was not called before.
But usually, e.g. in my example in the first post, it is okey. CLR
just suppresses that type of exceptions once they slip out of the
thread and process is not terminated. Nothing bad happens.
But for some reason, which I need to discover, some time CLR does not
suppress it and the process IS terminated. Moreover the stack trace
which I managed to log in that case (see my first post) using
UnhandledException event, does not consist my code, and doesn't give
me any chance to add try/catch(){ Thread.ResetAbort();} which will
prevent from slipping it outside.
.
- Follow-Ups:
- Re: Thread Abort and Unhandled Exception Event
- From: Peter Duniho
- Re: Thread Abort and Unhandled Exception Event
- References:
- Thread Abort and Unhandled Exception Event
- From: pawel . kedzior
- Re: Thread Abort and Unhandled Exception Event
- From: Göran Andersson
- Re: Thread Abort and Unhandled Exception Event
- From: pawel . kedzior
- Re: Thread Abort and Unhandled Exception Event
- From: Peter Duniho
- Thread Abort and Unhandled Exception Event
- Prev by Date: Re: Thread Abort and Unhandled Exception Event
- Next by Date: Re: How to determine a string is in valid dateTime format
- Previous by thread: Re: Thread Abort and Unhandled Exception Event
- Next by thread: Re: Thread Abort and Unhandled Exception Event
- Index(es):
Relevant Pages
|