Jon Kalb: Exception-Safe Coding in C++ (Part I)

CppNow · 18K views · 2012 · 1:30:07

Open on YouTube

C, C++, Rust, Go & systems languagesSoftware practice, open source & careerstalk

Why Stack Overflow recommends it

Stack Overflow users link it when answering questions about C++ exceptions, exception specifications, and exception handling best practices.

Recommended by 1 people across 1 different months, 2012 to 2015.

What it is

Jon Kalb's C++Now 2012 conference talk on writing exception-safe C++ code. It starts from the problem exceptions solve, covers common but misguided safety attempts, and presents guidelines and implementation techniques, including how to migrate an exception-unsafe legacy code base.

What people said

Recommends Xaqq · 2015-06 · Stack Overflow · on “What's the benefit of exceptions specification in Java?”

There is very interesting talk by Jon Kalb about writing exception safe code in C++. He explains why exception specification is a bad thing (the idea being that can't know for sure what will thrown to your face, so you should survive against anything). Talk url: [this video] (its ~3h long).

Cites Juraj Blaho · 2012-11 · Stack Overflow · on “Proper/elegant way of implementing C++ exception chaining?”

C++11 already has nested_exception [LINK] . There was a talk about exceptions in C++03 and C++11 at Boostcon/C++Next 2012. Videos are on youtube: [this video] [LINK]

Cites Andy Prowl · 2013-04 · Stack Overflow · on “Not All Control Paths Return a Value? Warning”

Any advice? The compiler is giving you the best advice. Not all the control paths in your function contain a return statement, and your function is supposed to return a value. If an exception is thrown and control is transferred to a catch handler, that handler will print something to cerr and then flow off the end of your function without actually return ing anything. This is Undefined Behavior . Per Paragraph 6.6.3/2 of the C++11 Standard: [..] Flowing off the end of a function is equivalent to a return with no value; this results in undefined behavior in a value-returning function . For default-constructible values, you could fix this by adding a return T() statement right before the end