List of Phobos functions that allocate memory?
Marc Schütz" <schuetzm at gmx.net>
Marc Schütz" <schuetzm at gmx.net>
Fri Feb 7 07:08:22 PST 2014
On Friday, 7 February 2014 at 14:42:18 UTC, Dicebot wrote:
> On Friday, 7 February 2014 at 14:26:48 UTC, Marc Schütz wrote:
>> Hmm... then what _does_ qualify as exceptional in your opinion?
>>
>> A logic error (i.e. a mistake on the programmers side)
>> doesn't, IMO, it should abort instead. On the other hand,
>> there is the class of situations where e.g. a system call
>> returns an error (say, "permission denied" when opening a
>> file, or out of disk space). Or more generally, an external
>> service, like a database or a remote server. However, I can't
>> see how these are fundamentally different from invalid user
>> input, and indeed, there's often not even a clear separation,
>> e.g. when a user asked you to read a file they don't have
>> access to.
>>
>> So, what's left then?
>
> It is exceptional situation if input is supposed to be valid
> but surprisingly is not. For example, calling `decodeGrapheme`
> on external string without making sure it is valid first.
If the function expects it to be valid but you pass it an invalid
value, you're breaking the contract, which is a logic error and
thus should be checked for by assert, not by an exception.
=> Case number one: logic errors, no exceptions should be used
here.
If however the function doesn't require it to be valid (for
`decodeGrapheme` the docs don't say anything, so I assume it
doesn't), then it needs to be able to handle invalid input, for
example by throwing an exception.
=> This is an example of case number two: user errors, exceptions
are okay here.
But Brad Anderson seems to disagree on case two (or maybe case
one?). Or is there a third type of situation not covered by these
two cases?
> Same goes for file - trying open a missing file is exceptional,
> but checking for file presence is not.
I agree here, checking for presence is not exceptional.
More information about the Digitalmars-d
mailing list