DIP 1002 (TryElseExpression) added to the queue

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Thu Sep 29 06:39:48 PDT 2016


On 9/29/16 7:02 AM, pineapple wrote:
> On Thursday, 29 September 2016 at 10:51:01 UTC, Nick Treleaven wrote:
>> Note that finally(bool) is more flexible than finally/else as you can
>> interleave code arbitrarily. __guard makes it clearer something
>> special is happening rather than just implicitly extending `try` scope
>> in the `else` clause. Also, 'else' is not clear enough IMO.
>
> While I think finally(bool) is a decent approach, the languages that
> currently integrate this concept into their error handling - Python and
> Ruby to my knowledge - all use `else`. Clarity is not a good argument,
> because those who are already proficient in languages other than D will
> expect the syntax to be consistent with other languages. It would be
> like some language using foolishly using `elsif instead of `else if`.
> (Dammit, Perl.)

In fact, finally(bool) can be extended to:

enum ExceptionStatus
{
    success = 0,
    caughtException = 1,
    uncaughtException = 2
}

finally(ExceptionStatus)

Which has also been requested in the past.

-Steve


More information about the Digitalmars-d mailing list