Suggestion: Syntactic sugar for Exception handling in D2
Robert Fraser
fraserofthenight at gmail.com
Sun Jun 21 13:20:02 PDT 2009
Ulrik Mikaelsson wrote:
> Tomasz Sowiñski Wrote:
>
>> I like it. Although it's only sugar you're right -- it helps reading a bit. But I would allow (or even require) "try" before a block of code:
>>
>> if (condition) try {
>> ...
>> } catch (Exception ex) {
>> ...
>> }
> Agreed. And while the use-case for if-statements may be rare, I can see a few cases in for-loops where it actually makes a little sense, but then it's better to be explicit about it;
>
> foreach (item; collection) try {
> process(item);
> } catch (StopException e) {
> break;
> }
As Tomaz pointed out, this already works for statements (if, while, for,
foreach, with, synchronized, etc.).
More information about the Digitalmars-d
mailing list