Throw or return a tuple

Mats Cronqvist mats.cronqvist@REDACTED
Mon Aug 15 17:17:35 CEST 2005


   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.

   mats


orbitz@REDACTED wrote:
> I find myself often confused about which to do, should I throw an 
> exception when an error happens in a function or always go with 
> returning {ok, Value} or {error, Whatever}.
> 
> Some people seem try to tell me that I should use {error, Value} and 
> "get out of your OO mindset with exceptions".  But I think that is 
> bull.  I don't see why exceptions should be purely considered OO and 
> erlang has exceptions, why shouldn't I use them?  That seems like the 
> talk of people afraid of change or something similar. The most 
> convincing argument for me to use exceptions is because I want to be 
> able to do:
> 
> foo(bar()) rather than {ok, V} = ...yadda.
> 
> What do people generally prefer? Are we moving towards more exceptions? 
>  OTP seems to use exceptions for somethings and an error tuple for others.
> 
> Thanks
> 



More information about the erlang-questions mailing list