'unwrap envy' and exceptions
Paul Backus
snarwin at gmail.com
Fri Sep 10 15:57:03 UTC 2021
On Friday, 10 September 2021 at 15:44:04 UTC, jfondren wrote:
> On Friday, 10 September 2021 at 15:26:18 UTC, Kagamin wrote:
>> Nullable doesn't replace exceptions, it specifies a value
>> which is legitimately absent, not due to an error
>
> Asking for the maximum of an empty array is an error case
> (hence D's minElement/maxElement thrown an AssertError, not
> even a catchable exception)
Strangely, there is no mention of this in the documentation for
either `minElement` or `maxElement`. And it's also inconsistent
with other similar functions in `std.algorithm.searching`; for
example, `minCount` and `maxCount` throw an `Exception` on an
empty range.
More information about the Digitalmars-d
mailing list