Exception on native thread crashes .Net application without exception

半腔热情 提交于 2019-12-05 14:00:38

You can't catch and manage exception thrown from another unmanaged thread.

When a method throws an exception the CLR will search for a handler only in the thread where the exception has been thrown. It's even understandable because the call stack of a thread begins with the thread itself.

You have a root exception handler because the CLR puts a handler at the top level (the one will invoke your filter) but this isn't true for unmanaged threads so their exception can't be forwarded.

The only solution for this situation is to catch exception in the thread where they are originated. If your thread function can throw an exception then add a catch there. Anyway not on the managed side. Managed/unmanaged boundaries are pretty thick here.

You may like to read this nice article about exception handling: http://www.microsoft.com/msj/0197/exception/exception.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!