Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Static constructors & Exceptions / & FileConduit

Moderators: kris

Posted: 03/15/07 16:33:08

Seems any exceptions that occur during static construction aren't caught and reported by Tango.. Im not sure whether this is by design or not but i think it'd be usefull if they were.


Author Message

Posted: 03/15/07 19:38:27

That's weird. They should be. _moduleCtor() is called within the compiler runtime's try block.

Posted: 03/15/07 20:16:09

When i compile this it just exits straight out with no message. Actualy a bit more experimenting and it doesnt seem to be catching exceptions at all. I move the file conduit line int to main() or put assert(false) in main() and it didnt catch that either.


int main() {

return 0;


class Foo {

static this() { auto FileConduit? file = new FileConduit?("C:\\this file deosnt exit.erm");; }


Posted: 03/16/07 00:46:42

Hm... works for me :p It's worth mentioning, however, that the message display format depends on whether the file member is null. If it is null then e.toUtf8 is called, which by default simply returns msg. If it is not null then the exception prints with the following format: "file(line): msg" This latter format is probably what you're used to. Here's an example of how to generate it:

void main()
    return 0;

static this()
    throw new Exception( "Danger!  Danger!", __FILE__, __LINE__ );


test.d(8): Danger!  Danger!

Posted: 03/16/07 02:07:22

Never mind, it's me being a f***wit, the error message is going to the console but cause im clicking on test.exe i dont get time to see it. I was just used to getting a message box on screen with dmd phobos, cause i'd started with the winsamp example.

It's funny realy, learning D has been easy and intuative (so far), it's learning to use command line tools and linking and all that stuff has caused me hours of head scratching.