Re: advice on best use of try catch throw
Send message is really not a good example, return value depends on the
message and GetError might indicate some minor problem in underling calls,
but yes you example will do
It makes sense in some context like :
void GetRect(RECT& rc) throw(CError &)
{
assert(::IsWindow(m_hWnd));
if(!:: GetWindowRect(m_hWnd, & rc))
throw(CError(GetLastError()));
}
//my preference still would be(it does not force you user into emergency
recovery mode) :
HRESULT GetRect(RECT& rc)
{
assert(::IsWindow(m_hWnd));
if(!:: GetWindowRect(m_hWnd, & rc))
return HRESULT_FROM_WIN32(GetLastError());
return S_OK;
}
"mr.sir bossman" <mrsirbossman@discussions.microsoft.com> wrote in message
news:EEBD46EF-B00F-4486-A6ED-8E691E689D3B@microsoft.com...
So something like this?
LRESULT SendMessage(UINT Msg, WPARAM wParam, LPARAM lParam) throw(CError
&)
{
assert(::IsWindow(m_hWnd));
::SetLastError(0);
LRESULT ret = ::SendMessage(m_hWnd, Msg, wParam, lParam);
DWORD error = GetLastError();
if(error != 0)
throw(CError(error)); //does formatmessage like you said.
return ret;
}