Home

lasterror

Lasterror is a term used in computer software to refer to the most recently reported error from a system, library, or runtime. It can be represented as an error code, a human-readable message, or both, and is often kept separate from normal program flow to aid debugging and error reporting. In many environments the stored information is thread-local to prevent races between concurrent execution units.

In the Windows API, the last error for the calling thread is retrieved with GetLastError, which returns

In C and POSIX libraries, the variable errno records the last error code for the calling thread;

Some programming environments expose a dedicated variable or function named lasterror or similar that holds the

Best practices include treating last-error information as potentially untrusted, avoiding leaking internal details in user-facing messages,

a
numeric
code.
The
code
can
be
translated
into
a
message
via
FormatMessage.
In
networking
sockets,
WSAGetLastError
may
be
used
for
the
last
error
on
the
Winsock
stack.
many
functions
set
errno
on
failure.
The
corresponding
human-readable
string
is
produced
with
strerror(errno).
textual
description
of
the
most
recent
error,
including
stack
traces
in
certain
runtimes.
In
languages
that
rely
on
exceptions,
the
last
error
may
be
captured
in
an
exception
object
rather
than
through
a
separate
last-error
variable.
and
logging
errors
for
debugging.
Clear
separation
of
error
codes,
messages,
and
context
helps
portability
and
security.