Re: Thread Abort and Unhandled Exception Event

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi Pete
I think you misunderstand the nature of "UnhandledException". It's an
event, not an exception handler.
I might have called that a handler, but I never thought so. The key is
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.


.



Relevant Pages

  • Re: Try Finally...
    ... >the application's default exception handler, ... the records are traversed and the stack ... stopping the whole shebang at that point, and terminating the app. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Bug in exception handling
    ... The exception that your button1_Click raises is not handled, ... Use add handler in your Main. ... plus a Try/Catch in my Main. ... Try/Catch in Main only catches exceptions if the constructor of the MainForm ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: UnhandledException in Windows Service
    ... event and the OnStart and OnStop service events in Try/Catch blocks ... handler for unhandled exceptions useful/needed in a Windows Service? ... > Asynchronous & catch the exception there, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Try catch and Resume
    ... You could also add try/catch as you go along (if you don't have a handler ... the exception is raised and you can correct before retrying the line). ... but not in debug mode). ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Goto inside a call statement?
    ... exception occurs in C there will be no indication in the source ... code of B that C's return will be to some handler in A. The ... The only exception handling system that I know intimately - the one designed for VMS - provides exactly for those scenarios in a way that is reasonably easy to use. ... to "clean-up" before terminating. ...
    (comp.lang.fortran)