Tricky code with exceptions
Mike James
foo at bar.com
Thu May 9 05:26:40 PDT 2013
"bearophile" <bearophileHUGS at lycos.com> wrote in message
news:pnwldlckpgrjvvujepzo at forum.dlang.org...
<SNIP>
> My D translation:
>
> import std.stdio;
>
> void main() {
> foreach (i; 0 .. 6) {
> writeln("Loop: ", i);
>
> try {
> try {
> if (i == 3)
> break;
> } finally {
> if (i % 2 != 0)
> throw new Exception("");
> }
> } catch (Exception e) {
> writeln("Caught");
> }
> }
> }
>
>
> It prints:
>
> Loop: 0
> Loop: 1
> Caught
> Loop: 2
> Loop: 3
>
> And then it crashes.
>
> Bye,
> bearophile
Strangely, if you replace the "break" instruction with "continue" (I know
it's pointless code), it also crashes...
Regards, Mike.
More information about the Digitalmars-d-learn
mailing list