digitalmars.D.learn - Tricky code with exceptions
- bearophile (56/56) May 09 2013 A little Java program I've just found in a blog post:
-
Mike James
(6/33)
May 09 2013
"bearophile"
wrote in message - Maxim Fomin (5/5) May 09 2013 It works on dpaste http://dpaste.dzfl.pl/fcd2f2b5 which seems to
- bearophile (7/13) May 09 2013 Vista 32. Probably I will add it to Bugzilla.
- Sean Kelly (1/1) May 09 2013 For what it's worth, this runs fine on 64-bit OSX.
- Brad Anderson (13/69) May 09 2013 I just tested this for you when you hopped in IRC but you left
- Brad Anderson (2/5) May 09 2013 Oh, and this was dmd 2.062 (just -m64).
- bearophile (5/6) May 09 2013 Thank you for the data point. So maybe the problem is only on 32
- evilrat (2/9) May 09 2013 win8 dmd 2.062 32-bit also crashes
- Juan Manuel Cabo (23/23) May 09 2013 Tested on Linux - Kubuntu 12.04 64bits
- Juan Manuel Cabo (6/8) May 09 2013 Mm, sorry!!, it did crash but I had dr watson disabled in that VM.
- Dan Olson (4/15) May 09 2013 Anybody looked at the assembly for the crashing executables? The truth
A little Java program I've just found in a blog post: class Flow { static public void main(String[] args) { for (int i = 0; i < 6; ++i) { System.out.println("Loop: " + i); try { try { if (i == 3) break; } finally { if (i % 2 != 0) throw new Exception(""); } } catch (Exception e) { System.out.println("Caught"); } } } } Its output: Loop: 0 Loop: 1 Caught Loop: 2 Loop: 3 Caught Loop: 4 Loop: 5 Caught 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
May 09 2013
"bearophile" <bearophileHUGS lycos.com> wrote in message news:pnwldlckpgrjvvujepzo 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, bearophileStrangely, if you replace the "break" instruction with "continue" (I know it's pointless code), it also crashes... Regards, Mike.
May 09 2013
It works on dpaste http://dpaste.dzfl.pl/fcd2f2b5 which seems to be based on linux 2.62. Which platform do you use? P.S. Seems we can define new kind of forum contribution - some code works as expected in language X, but equivalent code in D goes ballistic. This is very sad.
May 09 2013
Maxim Fomin:It works on dpaste http://dpaste.dzfl.pl/fcd2f2b5 which seems to be based on linux 2.62.On dpaste it also works on gdc2.060 and ldc2.060, both 64 bit.Which platform do you use?Vista 32. Probably I will add it to Bugzilla.P.S. Seems we can define new kind of forum contribution - some code works as expected in language X, but equivalent code in D goes ballistic. This is very sad.On the other hand often it's broken code in other languages that works as desired in D :-) Bye, bearophile
May 09 2013
For what it's worth, this runs fine on 64-bit OSX.
May 09 2013
On Thursday, 9 May 2013 at 11:24:03 UTC, bearophile wrote:A little Java program I've just found in a blog post: class Flow { static public void main(String[] args) { for (int i = 0; i < 6; ++i) { System.out.println("Loop: " + i); try { try { if (i == 3) break; } finally { if (i % 2 != 0) throw new Exception(""); } } catch (Exception e) { System.out.println("Caught"); } } } } Its output: Loop: 0 Loop: 1 Caught Loop: 2 Loop: 3 Caught Loop: 4 Loop: 5 Caught 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, bearophileI just tested this for you when you hopped in IRC but you left before I could tell you that a 64-bit Windows dmd build did not crash and here is the output. Loop: 0 Loop: 1 Caught Loop: 2 Loop: 3 Caught Loop: 4 Loop: 5 Caught
May 09 2013
On Thursday, 9 May 2013 at 18:24:46 UTC, Brad Anderson wrote:I just tested this for you when you hopped in IRC but you left before I could tell you that a 64-bit Windows dmd build did not crash and here is the output.Oh, and this was dmd 2.062 (just -m64).
May 09 2013
Brad Anderson:a 64-bit Windows dmd build did not crash and here is the output.Thank you for the data point. So maybe the problem is only on 32 bit Windows. Bye, bearophile
May 09 2013
On Thursday, 9 May 2013 at 20:33:17 UTC, bearophile wrote:Brad Anderson:win8 dmd 2.062 32-bit also crashesa 64-bit Windows dmd build did not crash and here is the output.Thank you for the data point. So maybe the problem is only on 32 bit Windows. Bye, bearophile
May 09 2013
Tested on Linux - Kubuntu 12.04 64bits dmd 2.058 -m32 dmd 2.058 64 bits dmd 2.062 -m32 dmd 2.062 and the output is this for all of the above: Loop: 0 Loop: 1 Caught Loop: 2 Loop: 3 Caught Loop: 4 Loop: 5 Caught Then, tested on Windows XP SP3 32 bits, dmd 2.062, and it DIDN'T CRASH. The output is: Loop: 0 Loop: 1 Caught Loop: 2 Loop: 3 --jm
May 09 2013
On Friday, 10 May 2013 at 01:05:39 UTC, Juan Manuel Cabo wrote:Then, tested on Windows XP SP3 32 bits, dmd 2.062, and it DIDN'T CRASH. The output is:Mm, sorry!!, it did crash but I had dr watson disabled in that VM. Confirmed adding a writeln("finished") after the foreach, which isn't reached. So It DID CRASH in Windows XP 32 bits. Sorry for the noise. --jm
May 09 2013
"evilrat" <evilrat666 gmail.com> writes:On Thursday, 9 May 2013 at 20:33:17 UTC, bearophile wrote:Anybody looked at the assembly for the crashing executables? The truth is in there.Brad Anderson:win8 dmd 2.062 32-bit also crashesa 64-bit Windows dmd build did not crash and here is the output.Thank you for the data point. So maybe the problem is only on 32 bit Windows. Bye, bearophile
May 09 2013