Search code examples
c++functionthrow

What is the benefit to limiting throws allowed by a C++ function?


What is the benefit of declaring the possible exception-throws from a C++ function? In other words, what does adding the keyword throw() actually do?

I've read that a function declaration such as void do_something() throw(); should guarantee that no exceptions originate from the do_something() function; however, this doesn't seem to hold true of functions called within do_something(), thus making it a weak guarantee.

Please outline the usefulness (and best-use cases) of this language feature.


Solution

  • No one explains this better than Sutter

    http://www.ddj.com/architect/184401544

    The short version is

    1. Never write an exception specification
    2. Except possibly an empty one