CppCon 2015: Andrei Alexandrescu “Declarative Control Flow"
CppCon2 HN recommenders · recommended in 2 months, 2016-2022
102K views · 11 years ago · talk · evergreen
Andrei Alexandrescu's CppCon 2015 talk on handling exceptional control flow declaratively in C++. It uses scope guards with success and failure variants, built on std::uncaught_exceptions, to replace ad hoc RAII classes and rethrowing try/catch blocks.
Pointed to in threads on defer, scope_exit and RAII as the clearest treatment of scope guards.
1:33:12De-fragmenting C++: Making Exceptions and RTTI More Affordable and Usable - Herb Sutter CppCon 2019
CppCon
90K views • 7 years ago
1:39:25CppCon 2016: Herb Sutter “Leak-Freedom in C++... By Default.”
CppCon
149K views • 10 years ago
1:12:27CppCon 2015: Andrei Alexandrescu “std::allocator...”
CppCon
196K views • 11 years ago
1:29:06CppCon 2015: Herb Sutter "Writing Good C++14... By Default"
CppCon
193K views • 11 years ago
57:39CppCon 2016: Chandler Carruth “Garbage In, Garbage Out: Arguing about Undefined Behavior..."
CppCon
94K views • 10 years ago
1:24:36C++ Exceptions for Smaller Firmware - Khalil Estell - CppCon 2024
CppCon
23K views • 1 year ago
1:54:00Can C++ be 10x Simpler & Safer? - Herb Sutter - CppCon 2022
CppCon
277K views • 3 years ago
1:40:46CppCon 2015: Bjarne Stroustrup “Writing Good C++14”
CppCon
351K views • 11 years ago
52:01CppCon 2017: Louis Brandy “Curiously Recurring C++ Bugs at Facebook”
CppCon
158K views • 9 years ago
59:58CppCon 2018: Nicolai Josuttis “The Nightmare of Initialization in C++”
CppCon
79K views • 8 years ago
1:15:46CppCon 2017: Matt Godbolt “What Has My Compiler Done for Me Lately? Unbolting the Compiler's Lid”
CppCon
178K views • 9 years ago
1:40:27CppCon 2014: Herb Sutter "Back to the Basics! Essentials of Modern C++ Style"
CppCon
323K views • 12 years ago
1:05:39The One-Decade Task: Putting std::atomic in CUDA. - Olivier Giroux - CppCon 2019
CppCon
11K views • 7 years ago
55:42CppCon 2019: Matt Godbolt “Path Tracing Three Ways: A Study of C++ Style”
CppCon
77K views • 7 years ago
1:00:21CppCon 2019: Matt Godbolt “Compiler Explorer: Behind The Scenes”
CppCon
29K views • 7 years ago
1:29:49Going Native 2012 Keynote Stroustrup
savage309
33K views • 14 years ago
1:47:45CppCon 2017: Herb Sutter “Meta: Thoughts on generative C++”
CppCon
105K views • 9 years ago
1:29:55Sorting Algorithms: Speed Is Found In The Minds of People - Andrei Alexandrescu - CppCon 2019
CppCon
184K views • 7 years ago
1:04:00CppCon 2015: Sean Parent "Better Code: Data Structures"
CppCon
106K views • 11 years ago
1:02:17'Fastware' - Andrei Alexandrescu [ ACCU 2016 ]
ACCU Conference
34K views • 10 years ago
5 comments from Hacker News
A count of the number of exceptions in-flight was added, replacing the boolean indication of whether an exception is in-flight. This allows the scope guard construct proposed by Andrei Alexandrescu to distinguish between a scope being left on success and on an exception being thrown. YouTube video about scope guard: ▶ this video Description of the change to the standard: link
I think scope or similar is good. Also, see related video here CppCon 2015: Andrei Alexandrescu “Declarative Control Flow" ▶ this video
yes, you always run defer. I don't see it in this proposal, but Most languages/frameworks that implement a defer also implement a "error defer" which only gets triggered on some sort of labeled early exit scenario, and some implement "success defer": (i believe this is scopeguard: ▶ this video )
Andrei Alexandrescu has a fun talk about implementing scope_exit using a new C++17 function: std::uncaught_exceptions (which is a tweak to std::uncaught_exception). Fundamentally, it doesn't really solve the destructor throwing exceptions issue though. ▶ this video
Google is an example that writing production code that doesn't use exceptions is possible, not that this is the right thing to do. They said that their decision was primarily legacy-motivated (in short, they were fearing that introducing exceptions in a non-RAII codebase would lead us to a long period of instability). I'll add that in some situations (e.g when freeing resources) the control flow gets very convoluted, and you don't want to deal with directly. See: Andrei Alexandrescu - Declarative Control Flow ( ▶ this video )