Home

Errordomain

Errordomain is a concept in software engineering referring to the source or category of an error. In many error-handling systems, errors are identified by a pair: a domain (or namespace) and a code. The domain groups related errors and helps determine how to present or handle them, while the code identifies the specific condition within that domain.

In Apple's NSError model, the domain is an NSString attached to an NSError object, distinguishing errors from

When handling errors, code typically switches on the domain and the code to determine the appropriate user-facing

In Swift, errors are often modeled with the Error protocol, but NSError bridging preserves the domain and

Outside Apple's framework, the errordomain concept appears as a general approach: separate namespaces for error codes

different
subsystems.
The
code
is
an
NSInteger
that
identifies
the
precise
condition
within
the
domain.
Standard
domains
include
NSCocoaErrorDomain
for
Cocoa
framework
errors,
NSURLErrorDomain
for
URL
loading
errors,
NSPOSIXErrorDomain
for
POSIX
errno
values,
NSOSStatusErrorDomain
for
OSStatus-based
errors,
and
NSMachErrorDomain
for
Mach
kernel
errors.
Applications
may
also
define
custom
domains
for
their
own
errors,
using
a
reverse-DNS
string
like
com.example.MyLibraryErrorDomain
to
avoid
collisions.
message
or
recovery
action.
The
NSError
object
also
carries
a
userInfo
dictionary
with
keys
such
as
NSLocalizedDescriptionKey,
NSLocalizedFailureReasonErrorKey,
and
NSRecoverySuggestionErrorKey
to
provide
more
context.
code
when
interacting
with
Objective-C
APIs.
Using
URLError,
Cocoa
error
codes
are
accessible
via
domain
constants
and
enumerations.
to
avoid
ambiguity
and
to
simplify
error
handling
across
modules.