Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should exceptions be used in modern C++? [closed]

Currently we throw only on unrecoverable failure resulting from an external source (like data for example) and have a single try catch around the entire execution.

When/Why/How should exceptions be used in modern C++?

Does C++11 change the answer to the above question?

like image 508
David Avatar asked Nov 05 '22 09:11

David


1 Answers

Regarding the first part of the question (best-practices), standard reference is "Exception-Safety Issues and Techniques" part of "Exceptional C++: 47 Engineering Puzzles, Programming Problems, and Solutions" by Herb Sutter.

Addressing the C++11 part -- the following references might be helpful:

New exceptions-specific features have been added:

http://www2.research.att.com/~bs/C++0xFAQ.html#rethrow

http://www2.research.att.com/~bs/C++0xFAQ.html#noexcept

Even seemingly unrelated features are in fact very much related as far as their applications go: "The uses of unique_ptr include providing exception safety for dynamically allocated memory [...]" http://www2.research.att.com/~bs/C++0xFAQ.html#std-unique_ptr

Exception specifications have been deprecated: http://herbsutter.com/2010/03/13/trip-report-march-2010-iso-c-standards-meeting/

like image 115
Matt Avatar answered Nov 09 '22 08:11

Matt