Home

Exceptions

An exception is an abnormal condition that interrupts a program’s normal flow of execution. In many programming languages, exceptions are objects that describe an error or unusual condition and can be raised when something goes wrong, such as a failed file operation or an invalid input. When an exception is raised, the runtime transfers control to an exception handler. If no handler is found, the exception propagates up the call stack and may terminate the program.

Exception handling provides mechanisms to recover from errors and to ensure resources are released. Common constructs

Languages distinguish between different kinds of exceptions. Some use checked exceptions, which must be declared or

Outside computing, the term exception also denotes an instance that does not conform to a general rule,

include
try,
catch,
and
finally
blocks,
or
equivalents.
Implementations
typically
unwind
the
call
stack
until
a
matching
handler
is
found.
During
unwinding,
finally
blocks
or
equivalent
clean
up
resources,
such
as
closing
files
or
releasing
locks.
caught
by
the
programmer,
while
others
treat
all
exceptions
as
unchecked
at
runtime.
Examples
of
typical
exception
categories
include
input/output
errors,
arithmetic
errors,
and
null
or
invalid
references.
Descriptive
messages
and
stack
traces
aid
debugging
but
should
not
be
relied
on
for
program
logic.
such
as
an
irregular
form
in
linguistics
or
a
provision
that
exempts
a
case
from
a
rule
in
law
or
policy.