Hacker News new | ask | show | jobs
by omnigoat 5707 days ago
You're making two mistakes: One about how exceptions work, and another by not considering our constraints.

Exceptions don't just add an overhead when they're thrown, they add overhead for every function call. How else would the exception-handling runtime know to unwind the stack to the correct addresses? It is this performance degradation that we avoid. Why? For the PC, it doesn't really matter. The XBox360 doesn't handle the performance hit very well. The compilers for the Nintendo DS (edit: and the Wii) don't even support exceptions, and the PSP is so crazily architectured that things like floating point numbers or exceptions can cause a framerate to drop from 300 to 12. I've not worked on the PS3. You must understand that these consoles and handhelds are designed very differently from PCs, and are never as powerful.

We do check for errors, we just stay away from exceptions. And dynamic casting, when we can (the DS does a freaking string compare against the vtable!).

1 comments

> Exceptions don't just add an overhead when they're thrown, they add overhead for every function call. How else would the exception-handling runtime know to unwind the stack to the correct addresses?

With unwind descriptors/exception handling tables, which can be stored in a read-only segment of the executable and don't need to be paged in until an exception occurs. They have no runtime performance cost until an exception is thrown.

Unwind tables are the default exception model on most modern gcc C++ targets. They're also the default exception model in Visual C++ x64, at least.

c.f.:

http://stackoverflow.com/questions/318383/exception-handling...

http://msdn.microsoft.com/en-us/library/1eyas8tf(VS.80).aspx

Yes, that's fair for the PC (I was aware of this for the PC, which is why I said exceptions don't really matter on the PC). But (from memory) I don't believe the Xbox allows for this, even though it uses a very similar variant of the same compiler. It's a moot point, though, for all the other reasons I mentioned. When you've got a cross-platform codebase - and there are precious few platform-exclusive codebases these days - it is far easier to turn exceptions off across the board than deal with individual platform's quirks.