1

I'm getting a ThreadAbortException in C# in generic try catch block (catching all exceptions) -- however, I'm unable to get a trace on it, indicating it was probably killed outside of managed code.

I get an HRESULT code of -2146233040, which when decoded:

FACILITY_URT 19 - .NET CLR

Code 0x1530 - COR_E_THREADABORTED

Thrown into a thread to cause it to abort. Not catchable.

Any ideas how to track this beast down?

ayu
  • 111
  • 1
  • 1
  • 6

1 Answers1

1

This is caused by a call to Thread.Abort() which raises a ThreadAbortException.

Note that you can't stop a ThreadAbortException from propogating, even though it's thrown by managed code. You can catch it, but you can't ignore it.

If you look at this link and search for COR_E_THREADABORTED you will see that it is used for a ThreadAbortException.

There might be a way to find where this exception is being thrown:

If you can run this under the Visual Studio debugger, go to menu item Debug | Exceptions, then tick the checkbox in the thrown column next to "Managed Debugging Assistants". (You could tick all the items in the thrown column if you like.) Then run the program under the debugger and see if anything pops up.

Matthew Watson
  • 104,400
  • 10
  • 158
  • 276
  • 1
    However, reading documentation, OP may want to try putting something in his `finally`: `ThreadAbortException is a special exception that can be caught, but it will automatically be raised again at the end of the catch block. When this exception is raised, the runtime executes all the finally blocks before ending the thread. Because the thread can do an unbounded computation in the finally blocks or call Thread.ResetAbort to cancel the abort, there is no guarantee that the thread will ever end.` – tnw May 03 '13 at 20:54
  • The thread should not be aborting, as I have no calls to Thread.Abort(). While I could reset the abort, this does not seem safe and does not help track down why the thread is aborting in the first place. – ayu May 04 '13 at 01:32
  • @ayu I added a last paragraph to my answer explaining how to turn on the "Managed Debugging Assistants" which can catch these exceptions when they are first thrown. – Matthew Watson May 04 '13 at 07:58
  • Matthew, they are all checked and while it does catch it, I still have no idea where the thread is being aborted from. All I get from the caught exception is a complus exception code. – ayu May 04 '13 at 19:21