Home

exceptionsafe

Exceptionsafe is a design principle in software engineering that concerns how code behaves when exceptions interrupt normal control flow. An exceptionsafe component aims to maintain program correctness, preserve invariants, and avoid resource leaks in the presence of errors.

Common levels of exception safety include: no-throw, which guarantees that a function will not throw; strong

To achieve exceptionsafe behavior, developers rely on techniques such as RAII (resource acquisition is initialization) and

The term is most commonly discussed in the context of C++, but the underlying principle applies across

See also: exception safety guarantees, RAII, resource management, strong exception safety, basic exception safety.

exception
safety,
where
if
an
exception
occurs,
the
system
state
is
unchanged
as
if
the
operation
had
never
started;
and
basic
exception
safety,
where
invariants
are
preserved
and
resources
are
not
leaked,
but
the
final
state
after
an
exception
may
differ.
A
function
may
provide
no
guarantee
about
its
post-state
beyond
preserving
invariants.
smart
pointers,
which
ensure
automatic
cleanup;
using
operations
that
offer
stronger
guarantees;
structuring
mutations
so
that
changes
can
be
rolled
back
or
isolated;
avoiding
throwing
in
destructors;
writing
exception-safe
constructors;
and,
in
languages
like
C++,
annotating
functions
with
noexcept
to
express
an
explicit
no-throw
intent.
languages
with
exceptions.
Different
languages
provide
different
mechanisms
for
expressing
guarantees
and
handling
failures,
yet
the
objective
remains
the
same:
minimize
unintended
side
effects,
manage
resources
reliably,
and
offer
predictable
failure
behavior.