Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The idiomatic way to solve the problem is not to indicate that your code can throw exceptions, but to implement exception safety in your objects. The standard defines several exception guarantees objects should implement:</p> <ul> <li>No-throw guarantee: The function will <em>never</em> throw an exception</li> <li>Strong exception safety guarantee: If an exception is thrown, the object will be left in its initial state.</li> <li>Basic exception safety guarantee: If an exception is thrown, the object be left in a valid state.</li> </ul> <p>And of course, the standard documents the level of exception safety for every standard library class.</p> <p>That's really the way to deal with exceptions in C++. Rather than marking which code can or can not throw exceptions, use RAII to ensure your objects get cleaned up, and put some thought into implementing the appropriate level of exception safety in your RAII objects, so they're able to survive without special handling if an exception is thrown.</p> <p>Exceptions only really cause problems if they allow your objects to be left in an <em>invalid</em> state. That should never happen. Your objects should <em>always</em> implement at least the basic guarantee. (and implementing a container class which provides the proper level of exception safety is an enlightening C++ exercise ;))</p> <p>As for documentation, when you're <em>able</em> to determine for certain which exceptions a function may throw, by all means feel free to document it. But in general, when nothing else is specified, it is assumed that a function may throw. The empty throw specfication is sometimes used to document when a function <em>never</em> throws. If it's not there, assume that the function may throw.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload