int
or bool
perror()
, the global errno
contains the last error codeperror()
usage in the Linux kernel …h()
only get h()
errorsh()
to g()
and g()
to f()
are not propagatedthrow
catch
try
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
std::domain_error
std::length_error
std::out_of_range
std::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
std::overflow_error
std::underflow_error
catch
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. It is a good idea to extract a function if more than one is needed.