A C error handling style that plays nice with C++ exceptions

If you've ever wondered why someone might throw an exception from a destructor, this article provides a legitimate example:

A C Error Handling Style that Plays Nice with C++ Exceptions

by Stefanus Du Toit

From the article:

By choosing a particular convention for a C API's error handling, we were able to very conveniently translate errors from the C API to C++ exceptions. ... Every experienced C++ programmer I know has opinions on how errors should be handled. I've found this style to be quite useful when layering C++ on top of C, and I think there's some beauty in the interplay between C and C++ here.

 

Add a Comment

Comments are closed.

Comments (1)

0 0

Agentlien said on May 5, 2014 01:29 PM:

This was a very interesting article and I haven't really seen anything quite like this pattern before. It's especialy fascinating to see the official C++ website (and Facebook group) linking to a blog entry which contains a valid use of throwing from a destructor. I wonder what Herb Sutter has to say about it.