[Haskell-cafe] Re: New Hackage category: Error Handling

Richard O'Keefe ok at cs.otago.ac.nz
Mon Dec 7 17:45:33 EST 2009

When I was working at Quintus, I came up with a classification
which I can simplify something like this:

   operating system fault
	Something bad happened (like a remote node going down) that was
	entirely out of your control.  There is nothing you can do to
	your program to prevent this.  Example: power failure.  It's
	still your problem to clean up on your way out.

   resource faults
	your program tried to do something possibly meaningful but
	the system ran out of some kind of resource (cpu limit,
	memory limit, disc quota, &c)

	You might respond to this by increasing the limit and trying

   representation faults
	your program tried to do something meaningful but the system
	was unable to represent the result (integer overflow, upper
	case of ÿ in a Latin 1 system, floating point overflow on a
	non-IEEE system, &c)

	Your program isn't *wrong* but you will still have to change it.

   existence errors
	Your program tried to do something with a (typically external)
	resource that doesn't exist (missing file)

	Your program could be wrong but probably isn't.
	You will have to create the resource or provide a different name.

   permission errors
	Your program tried to do something to a (typically external but
	not always) resource that you do not have permission to do
	(typically writing to a read-only file)

         You may have named the wrong resource.  If not, you may have to
	get the permissions for the resource changed, or ask someone
	else to run the program.

   domain errors
	A precondition on the input arguments of an operation was not
	satisfied (e.g., X/0, sqrt(-1), malformed file name, head []).

	Your program is definitely wrong.

   postcondition errors
	Your program invoked some operation and the precondition for
	the operation was satisfied, but when it completed, the
	postcondition was not.

	The operation you invoked is broken.  If it's yours, you will
	have to fix it.  If the precondition was not strong enough,
	it may be your program at fault.  Otherwise, until you can
	get a fix from someone, you will have to program around it.

I didn't find a simple error/exception distinction helpful, and
still don't.

Take the case of trying to write to "/dev/nul".  This is a permission
error.  If the program is responsible for the name being what it is,
it's a mistake in the program.  If the user typed the name in, it's
the user's mistake.  You really can't tell without tracing each value
to its origin.

I dare 

More information about the Haskell-Cafe mailing list