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

前端 未结 6 639
粉色の甜心
粉色の甜心 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:02

    You can use a Global Exception handler to catch all of the uncaught exception in the AppDomain:

    AppDomain currentDomain = AppDomain.CurrentDomain;
    currentDomain.UnhandledException += new EventHandler(UnhandledExceptionHandler);
    

    I think it would work for exceptions thrown from other threads as well

提交回复
热议问题