[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: error() or nil, 'error msg'
- From: Dirk Laurie <dirk.laurie@...>
- Date: Thu, 11 Sep 2014 07:41:45 +0200
2014-09-11 2:43 GMT+02:00 Rena <hyperhacker@gmail.com>:
> The idiom I've heard and used is that returning (nil, errmsg) is for
> runtime errors, and error() is for programming errors. So e.g.:
> return nil, "Failed to open file: access denied"
> vs:
> error("Invalid argument to method frobulate (expected number)")
The question one should ask is: could one reasonably expect
the calling routine have a nice way of recovering from this error?
If so, return nil,error_obj; otherwise abort.
And assert only tautologies, in order to assist documentation.
It says "If we get here, the following condition is guaranteed
to be true." in a way that inspires confidence.