4 ms·
Yes, plenty, including Google. If anything exceptions are declining in popularity, due to non-obvious and non-local effects. Exceptions are an uber-goto, that
by paulddraper 7y ago
Yes, plenty, including Google.
If anything exceptions are declining in popularity, due to non-obvious and non-local effects.
Exceptions are an uber-goto, that can jump outside entire functions. Some people still like that, but very disciplined code bases (of which there are a lot in C++) tend to avoid them.
At the very least, utility libraries like this one tend to err on the side of most compatible: header only, no exceptions, user-chosen allocators, etc.
- pansa2 7y agoThanks. Do you know what the knock-on effects are of disabling exceptions in modern C++? Are there parts of the language or standard library that won’t work without exceptions?
- paulddraper 7y agoThe standard library uses exceptions, but in ways that are avoidable. Not using exceptions does necessitate avoiding the `new` operator, or allowing your program to terminate on OOM. [1] https://stackoverflow.com/questions/37700365/if-youre-in-the-we-dont-use-exceptions-camp-then-how-do-you-use-the-standar https://stackoverflow.com/questions/37700365/if-youre-in-the... [2] https://news.ycombinator.com/item?id=13354027 https://news.ycombinator.com/item?id=13354027
- kabdib 7y agoMany of the large C++ projects I've been on are exceptionless, but do throw an OOM exception which is caught at a very high level. That's usually the point where a crashdump is taken and some other forensics are gathered; a decent strategy is to freeze threads (if you can), release some reserve memory and try to gather evidence. Doesn't always work . . .
- paulddraper 7y agoSome "exceptionless" projects actually disable exceptions entirely via compiler flag.
- joshuamorton 7y ago> Exceptions are an uber-goto, that can jump outside entire functions. Some people still like that, but very disciplined code bases (of which there are a lot in C++) tend to avoid them. I've never heard discipline as a reason to be exceptionless, its always been performance related (specifically performance predictability).
- paulddraper 7y agoDiscipline can be mean strong performance too. In any case, exceptions are really only a performance problem if there are frequent. [1] Modern compilers and machines have near zero overhead for unthrown exceptions and 20x the overhead of an if-else. Chances are quite good that you have bigger performance problems than exceptions. [1] https://stackoverflow.com/questions/13835817/are-exceptions-in-c-really-slow https://stackoverflow.com/questions/13835817/are-exceptions-...
- joshuamorton 7y agoLike I said, performance predictability, not raw performance. if/else have predictable performance characteristics, while exceptions are fast usually and then occasionally very slow. The idea being that in an area where you'd like performance to be predictable, even in cases of unexpected results, Sum types or if/else give the same performance all the time.
- rumanator 7y ago> Like I said, performance predictability, not raw performance. Your argument makes absolutely no sense. Exceptions are used to handle exceptional events, the kind of stuff that would crash and shutdown your program. Exceptions are used to establish sanity checkpoints where any exceptional event can be caught and either recover from it or fail gracefully. Performance is measured on the happy path, and exceptions fall in the exact opposite of the happy path.
- joshuamorton 7y ago
- rumanator 7y ago> Yes, plenty, including Google. Your statement is either disingenuous or entirely clueless. The only rationale that Google presented to not use exceptions is that they use a lot of legacy code that was designed without exception handling, and thus it's problematic for then to integrate modern C++ code with old exception-free code. For Google, the only problem with exceptions is their own personal technical debt. That's it. It's in their FAQ. Enough with this nonsense. https://google.github.io/styleguide/cppguide.html#Exceptions https://google.github.io/styleguide/cppguide.html#Exceptions > Exceptions are an uber-goto, that can jump outside entire functions. That statement is far from being correct or an appropriate description. Exceptions are as much like goto statements as are return statements, and no one in their right mind would describe a return statement as an uber-goto statement. > Some people still like that, but very disciplined code bases (of which there are a lot in C++) tend to avoid them. Again, that assertion makes no sense at all.