Let's improve D's exceptions

Dmitry Olshansky via Digitalmars-d digitalmars-d at puremagic.com
Mon May 18 07:56:00 PDT 2015


On 18-May-2015 17:18, Steven Schveighoffer wrote:
> On 5/18/15 8:20 AM, Atila Neves wrote:
>> One thing I like about `enforce` is that the program's run-time checks
>> become positive instead of negative statements which I think is a lot
>> more readable. i.e.
>>
>>      enforce(foo && bar > 4, "...");
>>
>> instead of
>>
>>     if(!foo || bar <=3) throw new Exception("...");
>
> Yes, but that's a minor nuisance. I often do not rewrite conditions by
> distributing the negation to avoid this problem. In that case, the
> "operation" becomes basically:
>
> if(!(...))
>
> We could introduce a new 'when' keyword:
>

Perl's unless would "solve" this nicely ;)


-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list