Team LiB   Previous Section   Next Section
throw operator Throws an exception

throw-expr ::= throw [assignment-expr]

The throw operator throws assignment-expr as an exception. The throw expression has type void. With no operand, throw rethrows the current pending exception. If no exception is pending, terminate( ) is called.

Example

template<typename C>
typename C::value_type checked_first(const C& c)
{
  if (not c.empty(  ))
    return c[0];
  throw std::out_of_range("container is empty");
}

See Also

expression, try, Chapter 3, <exception>, <stdexcept>

    Team LiB   Previous Section   Next Section