r/cpp • • Apr 19 '26

Adding Stack Traces to All C++ Exceptions

https://werwolv.net/posts/cpp_exception_stacktraces/
120 Upvotes

27 comments sorted by

View all comments

Show parent comment

1

u/johannes1971 Apr 19 '26

The complete refusal to treat nullptr as an empty string in various contexts (std::string, std::string_view, and std::format foremost amongst them) is yet another example of C++ only talking about safety, and not actually doing anything to make it happen.

And sure, you can absolutely argue that nullptr is an invalid value and is therefore always wrong. But it's also an extremely common value, especially when dealing with C-based libraries, and accepting it as it is commonly used in C would remove a landmine or two.

"But what if you want to know the difference between an empty string and a nullptr?" --> Then you can still handle it yourself, before passing the char* to the relevant C++ function.