Against enforce()

Andrej Mitrovic andrej.mitrovich at gmail.com
Wed Mar 16 20:51:10 PDT 2011


On 3/17/11, Adam D. Ruppe <destructionator at gmail.com> wrote:
> Daniel Gibson
>>    enforce(foo, new BlaException("bad!"));
>
> One use of enforce is something more like this:
>
> auto fp = enforce(fopen("my file", "r"), "cant open file");
>
> Which replaces:
>
> auto fp = fopen("my file", "r");
> if(fp is null) throw new Exception("cant open file");
>

Well that is pretty sweet. I didn't know enforce returned the type
back. Time to cut some lines in my code, yay.


More information about the Digitalmars-d mailing list