throw operator

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.


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>