DConf 2014 Keynote: High Performance Code Using D by Walter Bright

Andrei Alexandrescu via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Sun Jul 20 09:53:17 PDT 2014


On 7/20/14, 5:57 AM, bearophile wrote:
> In those slides as other member of the sum type they have used an
> enumeration of possible error conditions (or at first even just strings
> of the error messages), sometimes augmented with more information, like:
>
> | EmailNotValid of EmailAddress
> | DbAuthorizationError of ConnectionString * Credentials
> | SmtpTimeout of SmtpConnection
> | SmtpBadRecipient of EmailAddress


No, those would be stored with the exception (possibly as part of its 
dynamic type). That's the obvious way to achieve that in D; we don't 
want to copy verbatim what's most appropriate for other languages.

>> template bind(alias fun) { ... }
>>
>> such that given a function e.g.
>>
>> int fun(string a, double b);
>>
>> bind!fun is this function:
>>
>> Expected!int bind!fun(Expected!string a, Expected!double b) {
>>   if (a.sux || b.sux) return composeExceptions(a, b);
>>   return fun(a.rox, b.rox);
>> }
>>
>> There would also be bindNothrow:
>>
>> Expected!int bindNothrow!fun(Expected!string a, Expected!double b) {
>>   if (a.sux || b.sux) return composeExceptions(a, b);
>>   try return fun(a.rox, b.rox);
>>   catch (Exception e) return e;
>> }
>
> One of the main points of using those two railways is to avoid exceptions.

Avoid exceptions as control flow, not as means of passing error 
information around. I think D's exception chains are very good at the 
latter. We should use them.


Andrei


More information about the Digitalmars-d-announce mailing list