|
|
|
|
|
by kwant_kiddo
940 days ago
|
|
Okay, do you think the effort is worthwhile?
Or do you think migrating to a language with a bigger runtime would have been a better choice? Because that is usually the conclusion I make. If you can afford that the compiler emits code for exception handling in all your functions and pay rtti then maybe your problem does not need that kind of performance in the first place. And you get all the downsides of using C++, and don't benefit from the upsides => just write it in go/java/c# 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.