Skip to content
0:00 / 0:00

#scopeguard#raii#exceptionhandling

CppCon 2015: Andrei Alexandrescu “Declarative Control Flow"

CppCon

189K subscribers • 103 videos on Hallway • Conference channel

YouTube
  • Recommended by 2 people: 2 on Hacker News.
  • Presented by Andrei Alexandrescu, author and C++ researcher
  • Linked in the descriptioncppcon/cppcon2015

Advanced. Deep dive for people who know the field.

102K views11 years ago2 recommendations

Programming languagesSoftware designC++Design patterns

Andrei Alexandrescu presents a declarative approach to handling exceptional control flow in C++ using generalized scope guards.

Cppcon.org — Presentation Slides, PDFs, Source Code and other presenter materials are available at: github.com/cppcon/cppcon2015 — Getting exception handling right is a perennial problem in C++ that has eluded systematization. Not for much longer. New language and library developments make it possible to handle exceptions in a declarative manner, leading to drastic code simplification. This talk discusses an alternative approach to handling exceptional flow that eliminates the need for small ancillary RAII classes, try/catch statements that rethrow, and other cleanup mechanisms. The popular Scope Guard idiom gets a spectacular generalization. Statements specify in a declarative manner actions to be taken if the current scope is left normally or via an exception. The resulting code is simpler, smaller, and easier to maintain. — Andrei Alexandrescu is a researcher, software engineer, and author. He wrote three best-selling books on programming (Modern C++ Design, C++ Coding Standards, and The D Programming Language) and numerous articles and papers on wide-ranging topics from programming to language design to Machine Learning to Natural Language Processing. Andrei holds a PhD in Computer Science from the University of Washington and a BSc in Electrical Engineering from University "Politehnica" Bucharest. He works as a Research Scientist for Facebook.Website: erdani.comTwitter handle: @incomputable — Videos Filmed & Edited by Bash Films: BashFilms.com Work at Hudson River Trading (HRT): tinyurl.com/safxfctf

Why it's here

2 people recommend this

What people say. Recommended for its elegant generalization of the scope guard idiom to handle success and failure paths in C++.

Ace17on Hacker News • Recommends

On “Memory management in C programs (2014)”

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 ( link to this video )

uepon Hacker News • Recommends

On “Scope exit in C++11 (2012)”

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. link to this video

u/Classic_Department42in r/C_Programming • Mentions

On “Defer in C (exploiting goto)?”

I think I meant this presentation: link to this video But it is a long time ago i watched

dnauticson Hacker News • Mentions

On “A Defer Mechanism for C”

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: link to this video )

watmoughon Hacker News • Mentions

On “Ask HN: What should have been the term for RAII?”

I think scope or similar is good. Also, see related video here CppCon 2015: Andrei Alexandrescu “Declarative Control Flow" link to this video

einpoklumon Hacker News • Mentions

On “A Tour of C++ (Third edition)”

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: link to this video Description of the change to the standard: link