June 27, 2025Jun 27 In recent weeks, weâve explored language features and library features becoming constexpr in C++26. Those articles werenât exhaustive â I deliberately left out one major topic: exceptions. Starting with C++26, it will become possible to throw exceptions during constant evaluation. This capability is enabled through both language and library changes. Given the significance of this feature, it deserves its own dedicated post. C++26: constexpr Exceptions by Sandor Dargo From the article: P3068R6: Allowing exception throwing in constant-evaluation The proposal for static reflection suggested allowing exceptions in constant-evaluated code, and P3068R6 brings that feature to life. constexpr exceptions are conceptually similar to constexpr allocations. Just as a constexpr string canât escape constant evaluation and reach runtime, constexpr exceptions also have to remain within compile-time code. Previously, using throw in a constexpr context caused a compilation error. With C++26, such code can now compile â unless an exception is actually thrown and left uncaught, in which case a compile-time error is still issued. But the error now provides more meaningful diagnostics.  View the full article
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.