DIP 1002 (TryElseExpression) added to the queue
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Thu Sep 29 06:32:50 PDT 2016
On 9/28/16 6:12 PM, Idan Arye wrote:
> On Wednesday, 28 September 2016 at 21:00:00 UTC, Steven Schveighoffer
> wrote:
>> Declaring variables that you need in the right scopes is pretty
>> straightforward. Having scopes magically continue around other
>> separate scopes (catch scopes) doesn't look correct. I get why it's
>> desired, but it doesn't look clean at all.
>
> Consider this:
>
> try {
> auto foo = Foo();
> } catch (FooCreationException) {
> // ...
> } else {
> foo.doSomethingWithFoo();
> }
> // foo does not exist here
>
> versus this:
>
> Foo foo;
> try {
> foo = Foo();
> } catch (FooCreationException) {
> // ...
> } else {
> foo.doSomethingWithFoo();
> }
> // foo exists here - it could be initialized, it could be not...
This is what I meant:
{
Foo foo;
try {
foo = Foo();
} catch (FooCreationException) {
// ...
} else {
foo.doSomethingWithFoo();
}
// foo exists here, but may or may not be correct. Don't use it.
// in fact, don't write any code here.
}
// foo doesn't exist here, just like in other example.
-Steve
More information about the Digitalmars-d
mailing list