Name
throw operator — Throws an exception
Synopsis
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>
Get C++ In a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.