digitalmars.D.bugs - [Issue 11574] New: Improper behavior of scope(failure)
- d-bugmail puremagic.com (19/19) Nov 21 2013 https://d.puremagic.com/issues/show_bug.cgi?id=11574
- d-bugmail puremagic.com (7/7) Nov 22 2013 https://d.puremagic.com/issues/show_bug.cgi?id=11574
- d-bugmail puremagic.com (28/28) Nov 23 2013 https://d.puremagic.com/issues/show_bug.cgi?id=11574
- d-bugmail puremagic.com (37/38) Nov 25 2013 https://d.puremagic.com/issues/show_bug.cgi?id=11574
- d-bugmail puremagic.com (9/9) Nov 25 2013 https://d.puremagic.com/issues/show_bug.cgi?id=11574
- d-bugmail puremagic.com (28/28) Nov 25 2013 https://d.puremagic.com/issues/show_bug.cgi?id=11574
https://d.puremagic.com/issues/show_bug.cgi?id=11574 Summary: Improper behavior of scope(failure) Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: shammah.chancellor gmail.com 2013-11-21 18:40:30 PST --- It was brought to my attention that scope(failure) can prevent the bubbling of exceptions by returning from the failure statement. This is bad behavior as scope failures can unintentionally prevent other scope failures from occurring. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 21 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11574 2013-11-22 20:10:22 PST --- Created an attachment (id=1293) Shows how scope(failure) return's can prevent proper exception bubbling. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 22 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11574 yebblies <yebblies gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |yebblies gmail.com Please paste test cases inline whenever possible. import std.stdio; void someFunc() { scope(failure) { writeln("What?");} // <-- NEVER EXECUTED?! scope(failure) { writeln("Failed in someFunc()"); return; } throw new Exception("Exception!"); } void main() { try { someFunc(); writeln("Yay, someFunc() is nothrow"); } catch(Exception e) { writeln("An exception in main!"); } } -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 23 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11574 monarchdodra gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |monarchdodra gmail.comShows how scope(failure) return's can prevent proper exception bubbling."scope(failure)" doesn't return. It lives "inside" the function it is declared in. It "holds" a return statement. It "rethrows" only once at the end of its block, but you are explicitly allowed to place a control statement inside the scope to *not* rethrow. An example case would be: //---- import std.stdio; void main() { foreach(i ; 0 .. 10) { scope(failure) continue; //Ignore exception and power through writeln(i); throw new Exception(""); } writeln("done!"); } //---- Another example could be an "Exception to return code" case: //---- HRESULT foo() nothrow { scope(failure) return E_FAIL; code_that_might_throw_here(); } //---- So I think the behavior is correct. Maybe just not intuitive at first, or not correctly documented. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 25 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11574 2013-11-25 13:27:36 PST --- I understand what's happening, but I don't think scope(failure) should ever be used in this way. It's not what it was originally intended for, and can hide other scope(failures) without a compiler error being generated.. That's why I submitted the bug. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 25 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11574 2013-11-25 13:30:08 PST --- Also, see this -- scope(failure) unintentionally hiding an Error! import std.stdio; void someFunc() { scope(failure) { writeln("What?");} // <-- NEVER EXECUTED?! scope(failure) { writeln("Failed in someFunc()"); return; } try{ assert(0, "Hrm?"); } catch(Exception e) { writefln("Exception!"); } } void main() { try { someFunc(); writeln("Yay, someFunc() is nothrow"); } catch(Exception e) { writeln("An exception in main!"); } } -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 25 2013