December 13, 2017 Re: What's the proper way to use std.getopt? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Wey | On Tuesday, 12 December 2017 at 18:34:26 UTC, Mike Wey wrote:
> On 12-12-17 00:35, Seb wrote:
>> D style would be to use sth. like this (instead of try/catch):
>>
>> ```
>> scope(failure) {
>> e.msg.writeln;
>> 1.exit;
>> }
>> ```
>
> I might have missed something, but where is `e` defined in this case?
I was thinking the same and can't find anything in the documentation that states you can retrieve the exception that caused the failure by an "e" variable.
All I could find is that in case you need to use the exception you'd have to do a try/catch.
So ultimately that code wouldn't work, according to the language specs.
I haven't tested it, so I don't know if it's some hidden feature, but if it is, then I'm against it.
|
December 13, 2017 Re: What's the proper way to use std.getopt? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bauss | On Wednesday, December 13, 2017 06:55:46 bauss via Digitalmars-d-learn wrote:
> On Tuesday, 12 December 2017 at 18:34:26 UTC, Mike Wey wrote:
> > On 12-12-17 00:35, Seb wrote:
> >> D style would be to use sth. like this (instead of try/catch):
> >>
> >> ```
> >> scope(failure) {
> >>
> >> e.msg.writeln;
> >> 1.exit;
> >>
> >> }
> >> ```
> >
> > I might have missed something, but where is `e` defined in this case?
>
> I was thinking the same and can't find anything in the documentation that states you can retrieve the exception that caused the failure by an "e" variable.
>
> All I could find is that in case you need to use the exception you'd have to do a try/catch.
>
> So ultimately that code wouldn't work, according to the language specs.
>
> I haven't tested it, so I don't know if it's some hidden feature, but if it is, then I'm against it.
If it works, it's a bug related to code lowering (since scope statements are always lowered to try-catch-finally blocks). You're not supposed to have access to the exception in a scope statement.
- Jonathan M Davis
|
December 13, 2017 Re: What's the proper way to use std.getopt? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On Wednesday, 13 December 2017 at 07:37:17 UTC, Jonathan M Davis wrote:
> On Wednesday, December 13, 2017 06:55:46 bauss via Digitalmars-d-learn wrote:
>> [...]
>
> If it works, it's a bug related to code lowering (since scope statements are always lowered to try-catch-finally blocks). You're not supposed to have access to the exception in a scope statement.
>
> - Jonathan M Davis
Yeah that's what I thought.
Just tested and it doesn't allow you to.
|
Copyright © 1999-2021 by the D Language Foundation