wxAutomationObject how to catch exeptions

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
cutecode
Super wx Problem Solver
Super wx Problem Solver
Posts: 425
Joined: Fri Dec 09, 2016 7:28 am
Contact:

wxAutomationObject how to catch exeptions

Post by cutecode »

is it possible to cactch exeptions in class wxAutomationObject, when some error occurs?
In MFC I could do it like this

Code: Select all

	try
	{
		m_pCommand->put_Port(1666);
		_result = m_pCommand->Login();
	}
	catch( _com_error &e )
	{
		#define maxstr 4024 +1
		wxString lpsz;

		// Get info from _com_error
		_bstr_t bstrSource(e.Source());
		_bstr_t bstrDescription(e.Description());
		lpsz.Printf(_T("Exception thrown for classes generated by #import\tCode = %08lx\n\tCode meaning = %s\n\tSource = %s\n\tDescription = %s"),
			e.Error(), e.ErrorMessage(),(LPCTSTR) bstrSource,(LPCTSTR) bstrDescription);
		
		log_err(lpsz);
	}
	catch(...)
	{
		log_err(_T("*** Unhandled Exception from MSM_Login***"));
	}
But when I call wxAutomationObject and some error occurs, a popup window shows up. I don't want this window to be shown. I just want to log this error to my own wxWindow control
wx 3.1.6 win/mac/linux

regards,
Alexander Saprykin
https://v2.dental-soft.ru
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxAutomationObject how to catch exeptions

Post by PB »

Wrap the wxAutomationObject call in its scope where you create a wxLogNull instance to suprress the error message. I prefer to do it usually only in the debug builds though.

E.g.

Code: Select all

wxAutomationObject obj;
< ...some code... >
{
#ifdef NDEBUG        
   wxLogNull logNo;
#endif 
   < ...wxAutomationObject call... >
}
< ...more code... >
Unfortunately, the user code has no access to the actual error (such as HRESULT).
User avatar
cutecode
Super wx Problem Solver
Super wx Problem Solver
Posts: 425
Joined: Fri Dec 09, 2016 7:28 am
Contact:

Re: wxAutomationObject how to catch exeptions

Post by cutecode »

Helo, thanks for a hint.

After reading a discription of class wxLogNull, I've found class which satisfies my needs

Code: Select all

wxLogTextCtrl
example

Code: Select all

	wxLogTextCtrl* m_myLog;

	m_myLog = new wxLogTextCtrl(m_Text);
	wxLog::SetActiveTarget(m_myLog);
I also found class wxLogBuffer, but in my thread wxLogBuffer::GetBuffer() always returns an empty string
wx 3.1.6 win/mac/linux

regards,
Alexander Saprykin
https://v2.dental-soft.ru
Post Reply