Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This was a fairly common position when I was programming C++ over a decade ago.

Performance critical code like game engines, etc used to avoid exceptions like the plague. Not entirely surprised to find that’s still the case.



99.99% (maybe even more) of game engines is not performance critical code though. I guess the reason was a different one: for exceptions to work you need a sane memory model. It's very hard to write exception safe code in C++. A garbage collector is very helpful to accomplish that, and _this_ is the thing that's problematic, because it interferes with the 0.01% performance critical inner loops.


> It's very hard to write exception safe code in C++.

How? As long as RAII is used it's basically for free.


But there are a bunch of codes which are yet to be verified as exception-safe. And in the gaming industry it's often third party code that you cannot even inspect.


The right statement is then that it is very hard to retrofit exceptions in an non-exception safe code base. Exception safety itself is not easy, as it requires different code patterns and idioms than usual.

I believe that those idioms are useful and great even for non-exceptional code, but that's another story.


I agree and would replace my original statment of "It's very hard to write exception safe code in C++" with this.


With the 32-bit x86 ABI, exceptions hurt any time your code had the possibility of throwing one. The 64-bit ABI fixed that, and is REALLY slow when an exception shows up, but does not cost anything in the happy path.




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

Search: