A shocking realization:
I've been using C++ for my entire career.
Never used C++ exceptions. 😲
A shocking realization:
I've been using C++ for my entire career.
Never used C++ exceptions. 😲
Is there anybody actually using C++ at scale with exceptions deliberately turned on, and striving to write exception-safe code, remembering to specify noexcept where needed?
...and how are they enjoying it? :troll:
Kids, don't waste your time learning C++ exceptions... Learn good error-handling patterns from #Rust and #Go and apply them to your production #Cpp code!
Yes, you too @srevinsaju!
Those who stubbornly insist on using this terminally flawed C++ feature should at least watch this 1-hour long talk which summarizes a whole book on the two types of "noexcept" that you'll need to sprinkle all over your codebase (sometimes ever both on the same line!):
https://www.youtube.com/watch?v=3GwNjGMKBtI
@penguin42 😮
@codewiz Libreoffice seems to use them quite heavily.
@penguin42 They require all your code to be written in an exception-safe manner, though. It's a lot easier now that C++ has pivoted on RAII, move semantics and smart pointers.
But LibreOffice is an ancient codebase so is likely still using data structures with unclear ownership and semantics.
@codewiz I don't think exceptions are that bad as long as you only use them for things that are exceptional.
@penguin42 btw, C++ exceptions got better with the removal of the dynamic throw specifiers.
There's a proposal by Herb Sutter (author of the classic Exceptional C++) to move towards statically-typed exceptions, with a single type std::error:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0709r4.pdf
(oddly, https is broken on open-std.org)
#cpp #programming
@penguin42 Actually, this has a better summary and discussion:
https://www.reddit.com/r/cpp/comments/pfjtvr/what_is_your_review_of_c_exceptions_and/
@penguin42 C++11 introduced move semantics, which enabled unique_ptr as well as other innovations.
Rust's ownership model is designed around move semantics, while in C++ it has to coexist with the old copy semantics.
If an object has move semantics, it can be moved or swapped cheaply and without throwing. This assumption is essential for performant vectors and other data structures.
@codewiz Hang on, give me an explanation of dynamic throw and the changes in RAII, move semantics and smart pointers; I remember RAII was a thing long long ago in C++; that's mostly disappeared hasn't it?
@penguin42 RAII (strong resource encapsulation and ownership) is also a central design principle in Rust and modern C++:
https://en.cppreference.com/w/cpp/language/raii
#programming #cpp
Bobinas P4G is a social network. It runs on GNU social, version 2.0.1-beta0, available under the GNU Affero General Public License.
All Bobinas P4G content and data are available under the Creative Commons Attribution 3.0 license.