Suggestion: Syntactic sugar for Exception handling in D2

Ulrik Mikaelsson ulrik.mikaelsson at gmail.com
Sun Jun 21 12:42:10 PDT 2009


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;
}



More information about the Digitalmars-d mailing list