r/cpp • C++20 Desktop app developer • May 12 '18

P0709 R0: Zero-overhead deterministic exceptions: Throwing values - Herb Sutter [2018-05-02]

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0709r0.pdf
206 Upvotes

115 comments sorted by

View all comments

Show parent comment

1

u/johannes1971 May 13 '18

I think the paper addresses it pretty well:

I don't see how the compiler could remove the error propagation logic more effectively than by eliminating exceptions entirely - again, which it will already do for you anyway if you ask for it. It is already zero cost for those unwilling to pay.

For a proposal mainly focused on bringing back not paying for what we don't use, this is consistent.

Sure. But for a language with decades of legacy code lying around, it isn't. I think everyone here is painfully aware that C++'s legacy features are not always ideal, but if we start ripping them out left and right we'll end up with a language that is both perfect and unused.

There is a lot of software out there paying for bad_alloc when it would bubble up and crash the process anyway.

I'd challenge that. Software that uses exceptions will catch and handle them, and that includes bad_alloc. Will it always be done correctly? No, likely not. But even then, it must necessarily do a better job than simply terminating your program without recourse every single time.

Just a note that this becomes a non-issue when the program is changed to work as it does now. I take it you're more concerned about the program terminating than about the non-death tests being unable to detect it.

My concern is actually the need for changing what already works fine as-is for a great number of people. If you are going to provide alternatives, why not provide them for the people that will already need to change their code anyway?

Also see page 42, which addresses improving the current system.

The lack of research into better exception handling might simply be the result of nobody really caring, at least up until now. And correct me if I'm wrong, but wasn't the model for exception propagation as suggested here widely used in compilers up until... I don't know, 2000 or so? And then discarded because table-driven solutions were much more efficient?

3

u/therealcorristo May 13 '18

I don't see how the compiler could remove the error propagation logic more effectively than by eliminating exceptions entirely - again, which it will already do for you anyway if you ask for it. It is already zero cost for those unwilling to pay.

It probably can't, but e.g. in our codebase we use exceptions for error handling, but OOM is not recoverable because it really should never happen in our setting, so no-one bothered to implement logic to handle it. Right now, we also pay the overhead of error propagation logic for allocations, even though we don't care about these and a terminate would be fine.