digitalmars.D.learn - handling module ctor exceptions
- Darren Grant (4/4) Apr 17 2005 Hello,
- Andrew Fedoniouk (26/31) Apr 17 2005 This is an example from HelloWorld.d win32 it popups "Initalization Erro...
- Mike Parker (5/8) Apr 17 2005 When using WinMain as an entry point, yes, because you are required to
- Darren Grant (7/15) Apr 18 2005 OK, thanks for the information. What are other people doing given this
- Andrew Fedoniouk (4/7) Apr 18 2005 The best design thing you can do is
Hello, Is there a method for handling exceptions thrown by module static constructors? Regards, Darren Grant
Apr 17 2005
This is an example from HelloWorld.d win32 it popups "Initalization Error" MB on exceptions thrown in _moduleCtor(); // call module constructors extern (Windows) int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int result = 0; gc_init(); // initialize garbage collector _minit(); // initialize module constructor table try { _moduleCtor(); // call module constructors _moduleUnitTests(); // run unit tests (optional) } catch (Object o) // catch any uncaught exceptions { MessageBoxA(null, cast(char *)o.toString(), "Initalization Error", MB_OK | MB_ICONEXCLAMATION); result = -2; // failed } "Darren Grant" <Darren_member pathlink.com> wrote in message news:d3t9tq$1csq$1 digitaldaemon.com...Hello, Is there a method for handling exceptions thrown by module static constructors? Regards, Darren Grant
Apr 17 2005
Darren Grant wrote:Hello, Is there a method for handling exceptions thrown by module static constructors?When using WinMain as an entry point, yes, because you are required to initialize everything yourself, including module constructors. When using main as an entry point, no, unless you go in and modify the extern(C) main method in phobos/internal/dmain2.d and recompile phobos.
Apr 17 2005
In article <d3vii7$8rv$1 digitaldaemon.com>, Mike Parker says...Darren Grant wrote:OK, thanks for the information. What are other people doing given this limitation? I am wondering how many cases there are where you'd want to catch module ctor exceptions at all. Regards, Darren GrantHello, Is there a method for handling exceptions thrown by module static constructors?When using WinMain as an entry point, yes, because you are required to initialize everything yourself, including module constructors. When using main as an entry point, no, unless you go in and modify the extern(C) main method in phobos/internal/dmain2.d and recompile phobos.
Apr 18 2005
I am wondering how many cases there are where you'd want to catch module ctor exceptions at all.The best design thing you can do is to avoid exceptions thrown out of constructors. This is good in many senses and works for me many years.
Apr 18 2005