Using windows MFC C++. I have a third party app that calls a user-defined method in my CWinApp derived class. This method is called after InitInstance(). If there is an error in this method, such that an exception is thrown and caught in a try/catch block, I would like to exit the application from the catch block. What is the canonical and correct way to quit?
UPDATE:
Serge I believe is right that in InitInstance() returning false is the correct way to quit the application. However, now suppose I want to quit from a CDialog derived class's OnInitDialog() handler, what's the correct way to do that.
UPDATE 2
For me, I found calling PostMessage(WM_CLOSE) to be the best way from my non-modal CDialog derived class. All other methods of quitting I tried would raise some exception or other in some circumstances.
Here's an example of how I use it:
BOOL SomeDialog::OnInitDialog()
{
CDialog::OnInitDialog();
::OleInitialize(nullptr);
try
{
// ...load settings file here
}
catch(...)
{
PostMessage(WM_CLOSE);
return TRUE;
}
// return TRUE unless you set the focus to a control
return TRUE;
}