try/catch idiom in std.datetime

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Nov 18 06:53:07 PST 2013


On 11/18/13 1:56 AM, Daniel Murphy wrote:
> "Andrei Alexandrescu" <SeeWebsiteForEmail at erdani.org> wrote in message
> news:l6ccae$2cmt$1 at digitalmars.com...
>> 1. Fix scope(failure) and then use it.
>
> scope(failure) picks up Errors as well as Exceptions

That's fine. What the compiler should do for a nothrow function goes as 
follows. Consider:

void fun() nothrow
{
    statementsA
    scope(failure) statement
    statementsB
}

First off, statementsA must not throw. Then, if statementsB may throw, 
then look at what statement throws. If statement always throws an Error, 
then accept the code. This is because the scope(failure) effectively 
translates whatever exception into an Error, and it's legal for a 
nothrow function to throw Error.

Currently it looks like the presence of scope(failure) simply makes the 
function seem legit, no matter what.

void fun() nothrow
{
    scope(failure) {}
    throw new Exception("so sue me");
}


Andrei



More information about the Digitalmars-d mailing list