Exceptionally Bad: The Misuse of Exceptions in C++ & How to Do Better - Peter Muldoon - CppCon 2023
HTML-код
- Опубликовано: 20 дек 2023
- cppcon.org/
---
Exceptionally Bad: The Misuse of Exceptions in C++ & How to Do Better - Peter Muldoon - CppCon 2023
github.com/CppCon/CppCon2023
Exceptions were originally heralded as a new modern way to handle errors. However the C++ community is split as to whether exceptions are useful or should be banned outright. It has not helped the pro-exception lobby that in their enthusiasm to embrace exceptions, a lot of code has been written that puts exceptions in a bad light.
In this talk, We will present the original intent/history of exceptions and a brief overview of how exception mechanics work and how they circumvent the usual stack return mechanism to set the stage. we will then examine the philosophy of using exceptions and then the many cases of exception misuse including resource management, retries, hierarchies, data passing and control flow to name but a few.
For each case, we will then suggest better ways to handle each specific situation. In many cases, exceptions are often dropped in favor of some other more appropriate paradigm.
Finally, we will introduce situations that can truly benefit from exceptions and what a model exception class might look like.
---
Peter Muldoon
Pete Muldoon has been using C++ since 1991. Pete has worked in Ireland, England and the USA and is currently employed by Bloomberg as a senior Engineering Lead. A consultant for over 20 years prior to joining Bloomberg, Peter has worked on a broad range of projects and code bases in a large number of companies both tech and finance. Such broad exposure has, over time, shown what works and what doesn't for large scale engineering projects. He's a proponent of applied engineering principles, elegant solutions and expressive code.
---
Videos Filmed & Edited by Bash Films: www.BashFilms.com
RUclips Channel Managed by Digital Medium Ltd: events.digital-medium.co.uk
---
Registration for CppCon: cppcon.org/registration/
#cppcon #cppprogramming #cpp #exceptions
Anyone else find this a very simplistic talk, saying very obvious things, but the guy is sauntering around like he's some kind of genius?
Bjarne is the man for "taking the stand" after this talk.
if I ever make a joke language, functions will only be able to return error codes, to return data you'd have to throw it.
If everybody is getting C++ exceptions wrong, which they apparently are, sometimes even in the standard library (throwing exceptions for parse errors or file errors ?!?!?!), then maybe the problem is with exceptions, not the users of the language.
Exceptionally good talk. But the dry result is that exception problems far outweigh exception benefits and we have to deprecate them. Unfortunately, my experience does not count because I have been programming in C++ for only 25 years (out of 40) and C++ gurus are madly in love with exceptions.
OmegaException is "OmegaLul" omega bad class. I don't endorse it.
I met lots of developers who say they don't use exceptions in c++ but since they don't compile their libc++ or libstdc++ with -fno-exceptions they actually are using exceptions but just don't handle them. This was a good talk. One reason however I like to not have main() or thread's do catch(...) is because an unhandled exception in my mind is a logic error and relying on ... to catch it means you forgot to handle it at the appropriate spot. So in this case you will instead get std::terminate() called which typically is abort() and you get a core dump and you can debug easily at the point of the throw instead of the point of the catch.
There are ways to deal with out-of-memory, specifically by having a preallocated pool you can free up for "disaster recovery" (which is usually enough to make sure your persistent files/databases are in a consistent system before dying a clean death).
Thank you for the talk. Good notes about RTTI, and polymorphic-related. Anyhow sadly, first portion of the talk is too dry and too much on theorical in which speaker pre-warn it won't be.
That was an anazing talk Peter, thanks dor that! Returning to c++ after a decade and having ro know those new tools/approaches is priceles!
Great talk. Entertaining and concise
In one of my previous jobs. Adding a stacktrace to the systems base exception class was the single biggest productivity booster I added in one PR. Massive difference in debugging after that.
I'd be interested in the details of and rationale behind the special stack unwinding, and what are the recent efforts to mitigate the costs.
Fantastic talk! Coming from the GameDev world, I have had little experience with exceptions but this talk made me much more confident in them. Looking forward to putting this into practice in some none-engine code :)
As the speaker said, exceptions should be used for rare cases, or as some people say "for the truly exceptional".
Congratulations Peter! Top third most watched recent tech talk of the week:
I'm definitely going to use the omega exception class.
amazing content and well delivered. thanks!
My only problem with std::expected>, having used it recently, is that you can't automatically compose `errors...`, I really wish we could declare functions like `std::expected find(const T& collection, auto&& predicate) { ... return std::unexpected { SomeErrorNotPresentInTheSignature{...} };` This is the consequence of implementing stuff like expected, optional, variant at the library level and not the language level. Also, I do think it sucks that std::expected is defined as std::expected and not std::expected which would encapsulate the variant.
first 7 minutes in and I am loving it.