CLR terminates when a thread receives an unhandled exception

I have a background thread in my application. When one of the threads receives an exception that is not handled, all CLR outputs.

Is this normal behavior, or is it a bug in the CLR?

I expect the thread to exit, but the CLR will continue to work.

+5
source share
5 answers

.NET - , . , , , . , , , . .

AppDomain.CurrentDomain.UnhandledException, . - try...catch. , , . :

void MyThreadProc()
{
    try
    {
        // ... 
    }
    catch
    {
        // handle all exceptions
        // This is a BAD idea
    }
}

, , .

+7

, , 1.1. , . , . .. , , , . , , .. , , , .

+4

, , question .

+1
source

This is normal CLR behavior from version 2.0. Here is the MSDN post . To avoid completing the process, you can use something like this

<legacyUnhandledExceptionPolicy enabled="1"/>

which is impractical.

+1
source

This is normal behavior. You might want to catch an exception to prevent the application from exiting.

0
source

All Articles