DIP 1002 (TryElseExpression) added to the queue
crimaniak via Digitalmars-d
digitalmars-d at puremagic.com
Fri Sep 30 18:50:14 PDT 2016
On Thursday, 29 September 2016 at 10:51:01 UTC, Nick Treleaven
wrote:
> Assuming for a minute that we want some form of DIP1002, we
> might be able to extend the `try` scope in an interesting way:
>
> try {
> auto f = foo();
> }
> catch (Exception) {
> ...
> }
> finally (bool ok) { // true if no exception
> bar();
> __guard (ok) f.baz();
> f.baz(); // error: f not in scope
> }
>
My 5 cents, let's play:
try {
...
}
catch() { }
catch() { }
then { // I don't like idea to use 'else' very much. Please,
don't use 'else' with try!
...
}
finally {
}
let's be more generic
try {
...
}
catch() { }
catch() { }
then {
...
}
catch() { }
catch() { }
then {
...
}
catch() { }
catch() { }
...
finally {
}
(Hello from Javascript! But we have common scope here.)
or use guard in a more obvious place
try {
// in this code exceptions are routed to attached catch() blocks
catch(MyException); // yes, this guard looks as stand-alone
catch() to avoid new keywords, for example. May be bad idea, I
don't know.
// oops, in this code MyException ignores attached catch()
blocks because of guard
}
catch() { }
catch() { }
finally {
}
or make it again more generic
try {
// in this code exceptions are routed to attached catch()
blocks as usual
// ... but now catch() block can also be places inside of try
block
catch(MyException){
// process
// goto finally
}
// oops, this code below of catch(MyException), so...
}
catch() { }
catch() { }
finally {
}
As for me, last variant is the most straightforward.
More information about the Digitalmars-d
mailing list