[MS] Comparing exception behavior of magic statics, std::call_once , and std::async - devamazonaws.blogspot.com
We've been comparing magic statics, std:: call_ once , and std:: async , but one thing we haven't considered is their behavior in the event of an exception. For magic statics, if an exception occurs during initialization of the static, then the static is considered not to have been initialized. The exception propagates, and the next time the function is called, the language will try to initialize the static again. For call_ once , if an exception occurs during execution of the lambda, then the call is considered not to have occurred. The exception propagates, so the next time you call call_ once with the same once_ flag , it will try to call it. But std:: async is different. If an exception occurs during execution of the invocable, then the exception is saved, and when you ask the future or shared future for the result, the exception is rethrown. It does not try to execute the invocable again. Let's summarize this in a table. Before After success After exc...