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?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…