Re:Problems with C++ exceptions
by 1718627440 on Wednesday November 12, 2025 @07:00AM
(#45899107)
> Well, he's using try/catch locally. You're not supposed to handle errors locally with exceptions.
Tell that to Bjarne!
Regardless, in his example, he could achieve what he wants by wrapping the try in a lambda, and returning either the value from try or nullopt from catch. But clearly, that's just converting exceptions to another error-handling mechanism because he isn't doing it right.
He claimed that not handling an exception causes the program to crash, that's just plain incorrect. To be fair many people use the term "crash" liberally.
std::expected or equivalent is often used with std::error_code, which is an extensible system (error codes are arranged in categories) that among others interops with errno.