Jump to page: 1 2
Thread overview
[Issue 1513] New: try/catch/finally misbehavior on windows
Sep 18, 2007
d-bugmail
Sep 18, 2007
d-bugmail
Sep 18, 2007
d-bugmail
Sep 30, 2007
d-bugmail
May 29, 2010
Brad Roberts
Dec 10, 2010
Don
Dec 10, 2010
Brad Roberts
Dec 10, 2010
Don
Dec 12, 2010
Sobirari Muhomori
Dec 13, 2010
Don
Dec 13, 2010
Don
Dec 16, 2010
Don
Dec 29, 2010
Don
Jan 07, 2011
Don
Jan 08, 2011
Don
September 18, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1513

           Summary: try/catch/finally misbehavior on windows
           Product: D
           Version: 1.021
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: braddr@puremagic.com


bug.d
--------
import std.stdio;

void main()
{
    try
    {
        try
        {
            try
            {
            }
            finally
            {
                writefln("throw ex1");
                throw new Exception("ex 1");
            }

        }
        finally
        {
            writefln("throw ex2");
            throw new Exception("ex 2");
        }
    }
    finally
    {
        writefln("throw ex3");
        throw new Exception("ex 3");
    }
}
-------

dmd 1.021 on windows outputs:
$ ./bug
throw ex1
throw ex2
Error: ex2

dmd 1.021 on linux outputs:
$ ./bug
throw ex1
throw ex2
throw ex3
Error: ex3


-- 

September 18, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1513





------- Comment #1 from davidl@126.com  2007-09-18 01:03 -------
err, actually I prefer the windows under hood behavior. Windows prevents you replace the exception silently.

For a language to fix such a problem would need to have the stacktrace to locate where the exception thrown. It's a bit tough to fix the problem.


-- 

September 18, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1513





------- Comment #2 from davidl@126.com  2007-09-18 02:39 -------
if i put another try catch block wrap this , everything goes ok

seems it's not SEH related.

I tried some similar code with C __try __except __try __finally blocks. It works as expected


-- 

September 30, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1513





------- Comment #3 from thomas-dloop@kuehne.cn  2007-09-30 05:00 -------
http://www.digitalmars.com/d/statement.html#TryStatement
#
# If an exception is raised in the FinallyStatement and is not caught before
# the FinallyStatement is executed, the new exception replaces any existing
exception:
#

Added to DStress as http://dstress.kuehne.cn/run/f/finally_12_A.d


-- 

May 29, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=1513



--- Comment #4 from Brad Roberts <braddr@puremagic.com> 2010-05-28 22:51:25 PDT ---
I figured it'd been ages and maybe something had changed to maybe fix this bug.. nope:

dmd 1.061 on windows:
Error: ex 2
throw ex1
throw ex2

dmd 1.061 on linux:
throw ex1
throw ex2
throw ex3
Error: ex 3

dmd 2.046 on windows:
throw ex1
throw ex2
object.Exception: ex 2

dmd 2.047 (close to svn tip) on linux:
throw ex1
throw ex2
throw ex3
object.Exception: ex 3
--- <cut the stack trace> ---

So.. still different.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 10, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=1513


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au


--- Comment #5 from Don <clugdbug@yahoo.com.au> 2010-12-10 00:40:35 PST ---
The behaviour of this bug changed in DMD2.048, (possibly as a result of the fix
for bug 4339?)
Now, on Windows DMD2.050 produces:

throw ex1
throw ex2
object.Exception: ex 2
object.Exception: ex 1

Which I don't understand at all.

On D1.065, it is still:
throw ex1
throw ex2
Error: ex 2

Does it still work on D2 Linux?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 10, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=1513



--- Comment #6 from Brad Roberts <braddr@puremagic.com> 2010-12-10 00:46:09 PST ---
building against tip of trunk for dmd/druntime/phobos, the output:

throw ex1
throw ex2
throw ex3
object.Exception: ex 3
----------------
<snip stack trace>
object.Exception: ex 2
----------------
<snip stack trace>
object.Exception: ex 1
----------------
<snip stack trace>

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 10, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=1513



--- Comment #7 from Don <clugdbug@yahoo.com.au> 2010-12-10 01:48:42 PST ---
I think the D2 change was actually caused by druntime svn 358. Sean's comment:

Changed how exception chaining works.  Now, the original exception will be retained and continue propagating even if other exceptions are thrown during stack unwinding.  These exceptions will be chained via the 'next' pointer and regarded as collateral damage, as per TDPL.

Is that supposed to apply in this case? Either druntime is wrong, or (more likely) the spec needs to be updated.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 12, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=1513



--- Comment #8 from Sobirari Muhomori <dfj1esp02@sneakemail.com> 2010-12-12 09:39:15 PST ---
I'd prefer Sean's description, though the real issue is the 3rd finally block is not executed.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 13, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=1513


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |critical


--- Comment #9 from Don <clugdbug@yahoo.com.au> 2010-12-12 23:50:25 PST ---
Reduced test case. Only two finally clauses are required, provided that each try{} block contains a throw statement. This shows that nesting of finally statements doesn't work at all on Windows. Raising priority to critical.
----
import std.stdio;

void main()
{
    try
    {
        try
        {
            writefln("throw ex1");
            throw new Exception("ex 1");

        }
        finally
        {
            writefln("throw ex2");
            throw new Exception("ex 2");
        }
    }
    finally
    {
        writefln("finally");  // never reached
    }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2