Throw or return a tuple

Roger Price rprice@REDACTED
Tue Aug 16 12:28:04 CEST 2005


On Tue, 16 Aug 2005, Mats Cronqvist wrote:

>    throw an exception.
> personally, i believe that returning {ok,R}/{error,R} is ALWAYS wrong.
> e.g. file:open/2; as it is now, it will return {error,R} if there is
> some system resource missing (truly exceptional), or if you pass it bad
> data (e.g. a file that does not exist). in either case it should throw.
> i wonder where the {error,R} idiom came from... but there definitely
> seems to be a move away from it.

I seems to me that there is place for both {error,Reason}, or better,
{refused,R}, and exceptions.  Perhaps the criteria is that {error,R} is
for situations that may occur in the normal course of business which
prevent the function from completing, and exceptions are for things that
are not expected in normal business.

Examples: File permissions do not allow access - {refused,R}
          File system is on fire/has been stolen/power off - exception
                            (Don't laugh, I've had these things happen)

Roger




More information about the erlang-questions mailing list