static try?
dennis luehring
dl.soluz at gmx.net
Tue Nov 1 09:33:56 PDT 2011
Am 31.10.2011 02:21, schrieb Mehrdad:
> I've written this piece of code a fair number of times:
>
> static if (is(typeof(foo()))) { foo(); }
> else { bar(); }
>
> When the expression inside the condition (i.e. the call to foo()) gets
> complicated, you get lots of code duplication and things become harder
> to read.
>
> So I'm thinking, why not just introduce a 'static try'?
>
> Something like:
>
> static try
> {
> foo();
> }
> catch // (string ex) // perhaps let them know what the error is?
> {
> bar();
> }
>
> It's a clean and immensely readable improvement IMO, and it doesn't
> introduce any new keywords or any breaking changes to anything.
>
> How's the idea?
1. sorry but look like static exception based flow control - because of
the "try/catch" - and that is evil
2.
static try
{
}
introduces an compiletime scope - what would the following code mean?
static try
{
int x = 10;
foo();
int y = 20;
}
catch
{
bar();
}
More information about the Digitalmars-d
mailing list