Back to Basics: Exceptions - Klaus Iglberger - CppCon 2020

preview_player
Показать описание
---
Exceptions are the native error propagation mechanism in C++. If used properly, exceptions enable us to write simpler, more readable and more robust code. However, the path there can be tricky and unfortunately the exception mechanism isn't without flaws. This talk sheds somelight on the current issues with exceptions and why a large part of the C++ community isn't using them. It also gives guidelines and best practices on how to deal with exceptions and how touse them properly. It will go into detail about the exception safety guarantees, explains the tradeoffs between them, and demonstrates by example the individual steps necessary to reach them.

---

---

*-----*
*-----*
Рекомендации по теме
Комментарии
Автор

The top C++ experts tend to be trainers than actual programmers. It says a lot about a language when understanding its details is a field in itself.

bobweiram
Автор

You didn't need 1 hour to tell me not to use exceptions. Just the first 5 minutes convinced me.

ifilmhackersdotcom
Автор

Nice presentation, good to go over the fundamentals.
The slide said "How to deal with failing cleanup functions" in RAII but the discussion was more around which API to use to be notified of a failed attempt to close a file. I guess the message here could be "if you can't cleanup in the destructor - you're out of luck and have either leak the resource (for example, leave the mutex locked if that could fail) or terminate()"

alexanderchertov
Автор

Oh man.. is there a part of this video that recommends exception over features that exists in Modern C++? Did I miss something?

Btw, you know that presentation is really good when you thought the video ended in 30 minutes but actually has 1 hour runtime. Excellent video!

aldrinaldrin
Автор

The remarks around not throwing exceptions in case of bugs, and that asserts should be preferred, are odd to me. As far as I can tell, the only acceptable production-viable implementation of asserts is in terms of exceptions. A bug happening somewhere doesn't mean that your entire process needs to be unceremoniously brought down; you can at the very least still log what happened. In many cases, you should even be able to continue work on subsequent work units, canceling only the one that caused the problem. This is a perfect fit for exceptions.

isodoublet
Автор

Excellent presentation skills and very helpful contents!

patrickyeung
Автор

For slide 78, shouldn't this->pr be reset if w.pr is nullptr? Otherwise it'll have the old Resource.

dslundqvist
Автор

try {
auto i = try to_int("12");
auto d = try divide(42, i);
}

Who rated this "9" for noise? Were they thinking that higher number = more noise or something? It's terrible, hope it never becomes standard.

isodoublet
Автор

Slide 78. Don't we end up with multiple unique_ptr pointing to the same object? Shouldn't such a class be movable only ?

Radioguy
Автор

4:09 I still not use these Exception,

__hannibaalbarca__
Автор

TL;DR: Exceptions in C++ still suck and are not worth the effort. Maybe someday. Representative quote: "Exceptions are great because that's the only way to report errors from constructors! Oh, by the way, you cannot throw exceptions from destructors. Because ... it's complicated. So, yeah, just, well, write exception-safe code, man." I'm sticking to error-codes. Or, rather, absl::Status and absl:StatusOr. Let me know when exceptions no longer suck.

lajosnagy
Автор

At 11:11 there is a small misprint - The main function should have " return 0;" in another case this program have formally undefined behaviour. Super cool talk!

konstantinburlachenko