Particular exceptions names

kdevel kdevel at vogtner.de
Wed Jul 27 20:13:07 UTC 2022


On Wednesday, 27 July 2022 at 09:35:12 UTC, Ali Çehreli wrote:

> The following program show an example as well as 'enforce', 
> which I prefer over explicit if+throw+else:

Me too.

>   enforce!MissingArguments(args.length == 42,
>                            format!"Too few arguments: 
> %s"(args.length));

However, this particular form lowers the readability a lot. It is 
not the absence of arguments which is enforced but the length of 
the args array, i.e. the presence of the arguments. Therefore I 
prefer

    enforce (args.length == 42, new MissingArguments (...));



More information about the Digitalmars-d-learn mailing list