Hacker News new | past | comments | ask | show | jobs | submit login

Error handling with exceptions mostly perform better on the happy path than error codes and explicit checking. Granted, on the sad path they perform much worse.

Of course returning an error code, then not checking it performs better than exceptions, but that's comparing apples to oranges. The same applies for comparing the same program compiled with and without -fno-exceptions.




exceptions opens the door to your control flow being rug pulled in exchange for... an error message? realistically all you can do is wrap chunks of code in a `try { } catch (const std::exception &e)` block and hope they've implemented `std::exception::what`. an enum based approach gives you both better error messages and certainty of what errors can occur and when.


I replied to the overhead claim, you are moving the goal post.

I don't think we will ever have consensus about the control flow aspects of exceptions. For example once you employ RAII it's easier to write error-agnostic functions with exceptions than with error codes. With error codes you have to explicitly propagate the error up, while with exceptions it is automatic. Sometimes this is desirable. It's arguable that the function isn't really agnostic to exceptions, as you have to employ RAII to qualify, but in modern C++ codebases that should be the default, really.

Having said that you probably don't want to introduce exceptions to a large code base that was designed with no exceptions in mind, and this definitely applies to the Linux kernel.

edit: enum based approach giving better error messages, really? You get a fixed error message per enumeration, but you can have a custom error message with exceptions that include context.


Trolling still unwelcome.


that was a genuine response, not trolling. are you so emotionally invested in c++ that you take criticism against it as some kind of personal slight?


You wrote that if you were ever to code with exceptions, you would do a useless, disruptive thing no one recommends, and get undesirable results. Trolling.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: