CLR hosting exception handling in a non-CLR-created thread

后端 未结 1 697
北恋
北恋 2021-02-07 06:15

The issue:

An unhandled exception in a thread entering the CLR from unmanaged code does not trigger the \"normal\" unhandled exception CLR processing.

In the c

相关标签:
1条回答
  • 2021-02-07 06:56

    The update implies that you perhaps have a solution here. However, its solution won't work in all cases, so here is some more info.

    If you prefer CLR Unhandled Exception behaviour, then make that the outer-most program and call native code only to perform specific functions. That will ensure that the CLR gets control of the unhandled exception filter.

    If you want to retain your current structure and the C++ code you have is small, you could stop using the CRT at all (which will deny you a bunch of useful stuff including static constructors and C++ exception handling). That will ensure that the CLR gets the Unhandled Exception Filter.

    And, of course, you could simply call SetUnhandledExceptionFilter youself and get the behaviour you want.

    However, I think the best recommendation in this situation is to put an actual function with a catch block on the call stack of any thread where you want to do something when an exception happens and not rely on the UEF mechanism -- because in the context of a component system, it is always fragile as multiple users compete for it.

    Martyn

    0 讨论(0)
提交回复
热议问题