Will main() catch exceptions thrown from threads?

前端 未结 4 1592
难免孤独
难免孤独 2020-12-08 09:39

I have a pretty large application that dynamically loads shared objects and executes code in the shared object. As a precaution, I put a try/catch around almost everything i

4条回答
  •  不思量自难忘°
    2020-12-08 10:09

    Will main() catch exceptions thrown from threads?

    No

    When a thread throws an exception, it is not caught by main. Is this the standard behavior?

    Yes, this is standard behaviour.

    To catch an exception originating in thread X, you have to have the try-catch clause in thread X (for example, around everything in the thread function, similarly to what you already do in main).

    For a related question, see How can I propagate exceptions between threads?

提交回复
热议问题