How to handle exceptions raised in other threads when unit testing?

前端 未结 6 701
粉色の甜心
粉色の甜心 2021-01-17 10:43

When testing with Visual Studio Team Test unhandled exceptions in tests are caught and reported in the results. So I was kind of surprised to see the test hosting process (V

6条回答
  •  清歌不尽
    2021-01-17 11:13

    What I can say from the realm of C++ (if the knowledge can be translated) is that any exception thrown in a given thread can only be caught in that thread. If your main application launches three other threads, then you have to catch exceptions from each of the (now 4) threads independently. There is no way to implement a "global" exception handler in threaded code. This has to do with how threads (and processes) are implemented in the OS.

    But like I said, I don't know how closely that logic translates to C#, because it runs on top of a VM like Java.

提交回复
热议问题