5 ms·
> C++17 > Works with or without exceptions Is anyone using C++17 features with exceptions disabled? I thought the “no exceptions” people were generally only u
by pansa2 7y ago
> C++17
> Works with or without exceptions
Is anyone using C++17 features with exceptions disabled? I thought the “no exceptions” people were generally only using C++ as C-with-classes?
- cmrdporcupine 7y agoAll of Google's codebase, including Chromium, is OO C++ without exceptions. https://google.github.io/styleguide/cppguide.html#Exceptions https://google.github.io/styleguide/cppguide.html#Exceptions
- userbinator 7y agoIn other words, that codebase is without exceptions, without exception.
- DoofusOfDeath 7y agoExceptional observation.
- saagarjha 7y agostd::bad_alloc would like to have a word with you.
- MHordecki 7y agoAn exception that proves the rule.
- pansa2 7y agoThanks - I’d seen that section before, but hadn’t noticed that elsewhere the document says “code should target C++17“. Do you know if there are any parts of the C++17 language or standard library that are disallowed in Google’s code because those parts don’t work without exceptions?
- plorkyeran 7y agoNo, nothing in C++ has a hard dependency on exceptions. Custom allocators can be used to report allocation failures in some way other than throwing an exception, and other than that the standard library only uses exceptions to report precondition violations; things which are expected to sometimes fail (such as filesystem operations) can report error codes instead.
- jcelerier 7y agoLet's insist on > On their face, the benefits of using exceptions outweigh the costs, especially in new projects. However, for existing code, the introduction of exceptions has implications on all dependent code. If exceptions can be propagated beyond a new project, it also becomes problematic to integrate the new project into existing exception-free code. Because most existing C++ code at Google is not prepared to deal with exceptions, it is comparatively difficult to adopt new code that generates exceptions. Also let's note that there are more new C++ projects being created today that at any previous point in time. Propagating the -fno-exceptions meme is harmful to the whole community.
- paulddraper 7y agoYes, 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.
- platinumrad 7y agoI'm a "no exceptions, no exceptions" person. I mostly use C++ as C-with-templates, rather than C-with-classes, so C++17 is very useful to me.
- jandrewrogers 7y agoIn my experience, few people use exceptions in systems-style code like database engines, while still using every feature of the latest versions of C++. You can essentially use all of C++17 without them if you wish, and many people do. Definitely not C-with-classes style code.
- TuxSH 7y agoAccording to a recent talk from Herb Stutter (https://www.youtube.com/watch?v=ARYP83yNAWk https://www.youtube.com/watch?v=ARYP83yNAWk), as many as 20% of users fully ban exceptions and an additional 30% ban them partially. Even code doesn't actually reach the throwing paths, exceptions and RTTI induce a huge binary size overhead that is simply not acceptable if you have binary size constraints.
- ameixaseca 7y agoLow level programmers dislike exceptions because cost, high level (and some low level) programmers dislike exceptions because they make any reasoning about behaviour, resource leaking, etc impossible without looking at the full code, and even then the analysis is exponentially more difficult. This all applies regardless of the C++ standard, of course.