Will main() catch exceptions thrown from threads?

前端 未结 4 1585
难免孤独
难免孤独 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:26

    Your question is asking for something that isn't conceptually possible.

    Try blocks are defined as dynamic constructs of the stack. A try block catches exceptions thrown by code reached dynamically, by call, from its contents.

    When you create a new thread, you create a brand-new stack, that is not at all part of the dynamic context of the try block, even if the call to pthread_create is inside the try.

提交回复
热议问题