Ask HN: Big C++ projects that uses Exceptions and RTTI?
In my career the places I have been that uses C++ (with success) have all been using -fno-exceptions and -fno-rtti. All major open-source C++ projects seem to do the same. Chromium, LLVM, Electron, protobuf etc.
I guess if you want to excel at this language and build software (in C++) that people actually use you have to learn to use it without exceptions and rtti?
Some projects do use them like CMake. I think bloomberg also uses exceptions??
Maybe Meta also uses them but again if you look at another Meta C++ project like Hermes they prohibit use of both rtti and exceptions.
Do you use exceptions in your codebase? If you intend to keep coding in C++ are you not better off learning how to use the language without exceptions and rtti?
4 comments
[ 3.1 ms ] story [ 17.2 ms ] threadRTTI I’d say it’s best to only use in testing and debugging generally, it just plain isn’t reliable for the uses people seem to try to put it to.
I think another big issue is the complexity overhead of 'introducing' exceptions in a already complicated language. When you use exceptions the control flow of the program gets 'invisible' should you recover from a exception.
Also, just writing data structures in general that obeys the weak and/or strong exception guarantee is not very easy [1].
Like it makes writing (correct) C++ even harder than it already is.
[1]: https://en.cppreference.com/w/cpp/language/exceptions
Don’t get me wrong, maintaining exception guarantees and ensuring exceptions are appropriately caught is terrible. I much prefer working with optional and outcome and similar personally, but the assumption of exceptions is very deeply baked in, and avoiding them safely is a lot harder than one might guess.
Also, remember that while exceptions cost code size, they cost literally nothing in instructions executed unless an exception is actually thrown. That’s why the common nix implementation is called “zero cost exceptions”. In the happy path case they are faster than returning a discriminant. It’s not having exceptions available that makes code slow, it’s using them for things that are expected rather than unexpected or for control flow.
[1]: https://twitter.com/TimSweeneyEpic/status/122307740466037145...