int
or bool
perror()
, the global errno
contains the last error codeh()
only get h()
errorsh()
to g()
and g()
to f()
are not propagatedthrow
Where an error is detected, the function/method immediately returns from that point in the codecatch
Layered calls are returned (stack unwinding) until one that matches is foundtry
The catch
is associated with the code in the try
blockexception-handling code is error-handling code
std::logic_error
faulty logic within the program, such as violating logical preconditions or class invariants, and may be preventable
std::invalid_argument
argument value is not acceptedstd::domain_error
inputs are outside of the domain defined for the operationstd::length_error
exceed implementation-defined length limits for some objectstd::out_of_range
access elements out of defined rangestd::runtime_error
errors due to events beyond the scope of the program and where the program code cannot easily predict the error
std::range_error
the destination type cannot represent the result of a computationstd::overflow_error
arithmetic overflow errors, i.e., the result of a computation is too large for the destination typestd::underflow_error
the result of a computation is a subnormal floating-point valuecatch
Handlersconst
and volatile
are ignoredcatch (...)
matches any typecatch (Foo& e)
matches any object of type Foo or any object of any class derived from Footry
per Functionint
and char*
, but more challenging to determine what the error isstd::exception
catch
handlers for std::exception
will catch your throw
&
const
is thrown away; not concerned about the advantages of const at this pointthrow;
noexcept
specifiervoid f() noexcept;
void f();
void f() throw();
void f() throw(std::exception);
std::exception
and familytry
block per function. Good idea to extract function if more than one is needed