Article

Comparing exception behavior of magic statics, std::call_once, and std::async

The Old New Thing ·The Old New Thing ·Published 2026-09-18 ·5 min read

This article discusses the differences in exception handling between magic statics, std::call_once, and std::async in C++. It explains how each mechanism behaves when an exception occurs during initialization or execution.

From the article

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.


Share this resource


Discovered 2026-09-23 Source The Old New Thing Archive 2026-09 →