Live data from Hacker News

Current hardware trends make C++ exceptions harder to justify

open-std.org

21–30 of 516 posts

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

#21
Another problematic area is RTTI and dynamic_cast. Chromium disables both that and exceptions. As a replacement in few places where dynamic_cast can be useful Chromium adds a virtual function to the base class to return the subclass or null.

Chromium code replaces exceptions with boolean flags and logging or code to kill the current process for bad cases like out-of-bound access.

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

#22
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.

Since exception handling in desktop runtime environments usually takes an unbounded amount of time, it’s not good practice to use them in your main loop since you have to guarantee a new frame at 60Hz.

You can definitely do it but you’d be conceptually allowing for frame skips in your codebase. It could be difficult to audit and remove this assumption if down the road you wanted to tighten up your main loop code.

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

#23
I always avoid C++ exceptions, and also try to avoid dynamic memory allocations, smart pointers and RTTI etc whenever possible. This is pretty common in latency and (pseudo) real-time performance critical work, such as robotics control and 3d gaming.

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

#24
> It breaks the existing ABI, and all shared libraries would have to be compiled with the new model, as otherwise unwinding breaks.

I am convinced that maintaining ABI is a huge technical debt to C++. And that is largely occasioned by shared libraries.

Rust IMO made a fantastic decision to emphasize source distribution (and making it super easy via cargo and crates).

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

#27
Why do we need to have ambient control flow? This is what exception handling is, it's a hidden control flow.

I don't use them. I just create an error type and pass that around.

The only legitimate exception I will accept is when you access invalid memory. That's a special case and depending on the environment something extraordinary must happen.

But exceptions and exception handling just creates annoying code. It doesn't add value, not really.

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

#28
post #2

That's why we disable exceptions in video games.

We disable exceptions in video games due to lock contention when throwing exceptions on multiple threads in high core count situations?

No.

We disable exceptions in video games for dumb historical reasons that no longer apply.

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

#30
post #27

Why do we need to have ambient control flow? This is what exception handling is, it's a hidden control flow. I don't use them. I just create an error type and pass that around. The only legitimate exception I will accept is when you access invalid memory. That's a special case and depending on the environment something extraordinary must happen. But exceptions and exception handling just creates annoying code. It doe…

There are some kinds of errors that can’t be handled locally, but do need to be handled globally, or generically higher in the call chain. Continuing execution after the error occurs will make the problem worse. Exceptions allow you to cease execution without putting an if statement after every function call.
Post reply on HN