A domain error occurs when an input argument is of the right type but
there is something wrong with its value. For example, the second argument to
open/3 is supposed to be an atom that represents a valid mode for opening
a file, such as
write. If a number or a compound term is given
instead, that is a type error. If an atom is given that is not a valid mode,
that is a domain error.
The main reason that we distinguish between type errors and domain errors is that they usually represent different sorts of mistake in your program. A type error usually indicates that you have passed the wrong argument to a command, whereas a domain error usually indicates that you passed the argument you meant to check, but you hadn't checked it enough.
The exception code associated with a domain error is
domain_error(Goal, ArgNo, DomainName, Culprit, Message)
The arguments correspond to those of the exception code for a type error,
except that DomainName is not in general the name of a unary
predicate: it needn't even be an atom. For example, if some command
requires an argument to be an integer in the range 1..99, it might use
between(1,99) as the DomainName. With respect to the
example under Type Errors, if the month had been given as 13 it
would have passed the type test but would raise a domain error.
For example, the goal
raises the exception
The Message argument is used to provide extra information about the problem.
Some DomainNames recognized by the system include:
0-- no domain name specified
'atom or list'
)-- 'something between L and H
)-- a member of the set List
)-- the value X