www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Bizarre Exception/Throwing bug

reply John Demme <me teqdruid.com> writes:
Someone recently posted a bizarre bug concerning my mango containers
library.  Before spending a lot of time trying to boil it down to something
Walter can easily work with, I though I'd post here to see if anyone had
any suggestions.  Here's the code concerned:
------------
import std.cstream;
import mango.containers.ArrayList;

class CommandLine {
  // comment/uncomment the following line
  ArrayList!(int) paramList;
}

int main( char[][] args ) {
  return 0;
}

unittest {
  void testBoolParam() {
    try {
      dout.writefln( "before except" );
      throw new Exception( "uups" );
    } catch (Object o) {
      dout.writefln( "caught" );
    }
  }

  testBoolParam();
}
------------------------------
Compiled with build and the -unittest option:
When the ArrayList!(int) line is commented out, the program catches the
thrown exception and outputs "caught".  When it's commented in, the
exception isn't caught and the program outputs "Error: uups".  In both
cases "before except" is outputted first, as one would expect.

If the function inside the unittest block is removed and just the try is in
there, then it works properly (and catches the expception).  Also, if the
ArrayList!(int) line is put at the module scope or inside the main
function, it works properly.

The supporting mango.containers code can be browsed at:
http://svn.dsource.org/projects/mango/trunk/mango/

I don't think mango.containers has any other dependencies within mango, so
if you want to compile the example, you can just download that directory.

I can't make heads or tails of this one, and boiling it down is gunna take a
lot of time.  Any suggestions?

Any help with this one would be appreciated.

Thanks,
John Demme
Dec 04 2005
parent Frank Benoit <lastname tionex.de> writes:
Hi

Now I tried to use another implementation of list. This time mintl and got
the same behaviour. Even without the -unittest and the brand new dmd
v0.141.

frank lingurke:~/d$ ../buildd -DCPATH../dmd/bin -full ut2.d
gcc mintl/mem.o mintl/sorting.o ut2.o mintl/list.o mintl/share.o -o ut2
-lphobos -lpthread -lm
frank lingurke:~/d$ ./ut2
before except
Error: uups

Frank
--------------------------------------------------------
import std.cstream;
import mintl.list;

class Cls
{
        List!(int) l;
}

int main( char[][] args )
{
        void innerFunc()
        {
                try
                {
                        dout.writefln( "before except" );
                        throw new Exception( "uups" );
                }
                catch
                {
                        dout.writefln( "caught" );
                }
        }
        innerFunc();
        return 0;
}
Dec 05 2005