lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] Catching exceptions thrown in OnInit()


From: Greg Chicares
Subject: [lmi] Catching exceptions thrown in OnInit()
Date: Wed, 28 Jun 2006 17:03:17 +0000
User-agent: Thunderbird 1.5.0.4 (Windows/20060516)

Vadim--In OnInit(), I'm doing some things that can throw exceptions.
I observe that my overridden OnUnhandledException() handles them;
the documentation for that virtual function says
  "This function is called when an unhandled C++ exception occurs
  inside OnRun()..."
which I think isn't exactly correct, and
  "if you want to really handle the exception you should override
  OnRun() and put a try/catch clause around the call to the base
  class version there."
which didn't work when I tried it. I think that ought to be changed
as follows; would you please let me know if I've misunderstood?

First, for wxmsw at least, I can demonstrate with ::MessageBox()
calls that OnUnhandledException() handles exceptions thrown in
OnInit() as well as in OnRun(). Does that sound right? At least
that's true of the 'skeleton' trunk in our cvs. If it sounds
strange, then maybe I'm doing something unconventional.

Second, and subject to the same disclaimers, I think that the advice
to insert try and catch into OnRun() should apply to OnInit(), too.

At any rate, that's what seems to work for me, while nothing else
seems to work, but I thought it would be best to ask your opinion
before changing this in the 'lmi' trunk that we use for production.

One change I certainly must make anyway is in my safe-messagebox
function for msw:

    HWND handle = 0;
    wxWindow* top_window = wxTheApp->GetTopWindow();
    if(top_window)
        handle = reinterpret_cast<HWND>(top_window->GetHandle());
    ::MessageBox(handle, message, "Error", MB_OK | MB_ICONSTOP | MB_TASKMODAL);

which clearly should check whether wxTheApp is null before trying
to dereference it.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]