Live data from Hacker News

Current hardware trends make C++ exceptions harder to justify

open-std.org

11–20 of 516 posts

Re: Current hardware trends make C++ exceptions harder to justify

#11
post #2

That's why we disable exceptions in video games.

For AAA / high-performance / console / close-to-the-metal video games, at least.

There are tons of games where exceptions are perfectly fine. Though still more often used for "probably going to crash soon" situations than otherwise, I'd wager.

Re: Current hardware trends make C++ exceptions harder to justify

#12
This somehow reminded me, wasn't there a competition years back to see who could generate the most compiler error output with the least amount of C++? A few too many templates and you could generate terabytes. Edit: don't think it was this but this is still a fun read https://codegolf.stackexchange.com/questions/1956/generate-t...

Re: Current hardware trends make C++ exceptions harder to justify

#13
I am glad more people are raising the issue with C++ exceptions. Unfortunately I don’t think the argument made in this article is compelling enough. Bjarne is against replacing the current model and has written an entire article responding to various criticisms of the current model. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p194...

In particular he has already responded to the efficiency argument with the counter argument that current implementations can be optimized. Even if that optimization process breaks ABI compatibility, it’s still better than breaking source compatibility, which is usually what is being proposed. He is right about that so I don’t think efficiency arguments are going to sway him.

I used to embrace C++ exceptions until I had to use C++ in non-conventional environments. For me C++ exceptions are wholly inappropriate for real-time programming since it’s difficult to statically quantify how much time an exception handling sequence may take. There’s also the issue of it requiring malloc() which has its own issues from an interface standpoint in the real-time context. To avoid unbounded malloc, you’d have to set aside a per-thread area for exception storage and require that you never throw an exception value past a certain size.

Re: Current hardware trends make C++ exceptions harder to justify

#14

Wouldn’t changing the global mutex into a read/write be a simple way to fix things? Shared libraries changing the exception table at the same time as exceptions being thrown seems rare. Might also be fixable in an API-preserving way… Edit: nope. This idea is discussed later in the paper (not fully ruled out but the answer may still require ABI changes for more subtle reasons)

I think this is addressed in the article in the section starting "A less radical change would be to change the global mutex into an rwlock, but unfortunately that is not easily possible either..."

Re: Current hardware trends make C++ exceptions harder to justify

#15

Wouldn’t changing the global mutex into a read/write be a simple way to fix things? Shared libraries changing the exception table at the same time as exceptions being thrown seems rare. Might also be fixable in an API-preserving way… Edit: nope. This idea is discussed later in the paper (not fully ruled out but the answer may still require ABI changes for more subtle reasons)

> A less radical change would be to change the global mutex into an rwlock, but unfortunately that is not easily possible either. Unwinding is not a pure library function but a back and forth between the unwinder and application/compiler code, and existing code relies upon the fact that it is protected by a global lock. In libgcc the callback from dl_iterate_phdr manipulates shared state, and switching to an rwlock leads to data races. Of course it would make sense to change that, but that would be an ABI break, too.

Re: Current hardware trends make C++ exceptions harder to justify

#16
I've never liked exceptions, its always awkward combination with returning null or throwing exceptions, or error codes. It always ends up breaking some abstraction making it leaky - eg read_doc throws a file exception, or web exception or higher level exception that has no useful detail.

I'm really heartened in the last few years that FP popularity has caused more people to avoid exceptions and even golang doesn't support them.

Re: Current hardware trends make C++ exceptions harder to justify

#17
post #3

> Root cause > Traditional C++ exceptions have two main problems: > 1) the exceptions are allocated in dynamic memory because of inheritance and because of non-local constructs like std::current_exception. This prevents basic optimizations like transforming a throw into a goto, because other parts of the program should be able to see that dynamically allocated exception object. And it causes problems with throwing ex…

I'm relatively new to C++ and I found absl::StatusOr and its helper macros to be extraordinarily pleasant.

Re: Current hardware trends make C++ exceptions harder to justify

#18
post #3

> Root cause > Traditional C++ exceptions have two main problems: > 1) the exceptions are allocated in dynamic memory because of inheritance and because of non-local constructs like std::current_exception. This prevents basic optimizations like transforming a throw into a goto, because other parts of the program should be able to see that dynamically allocated exception object. And it causes problems with throwing ex…

[deleted]

Re: Current hardware trends make C++ exceptions harder to justify

#19

Very interesting that exceptions have much less overhead on the happy path than Rust/Haskell style Either types (std::expected): > For fib we see a slowdown of approx. 60% compared to traditional exceptions, which is still problematic.

I'm not convinced a recursive implementation of `fib` is a reasonable example to draw such a conclusion.
Post reply on HN