When implementing COM components, one must carefully observe the prohibition on allowing exceptions to escape out to the context of the caller. But implementing COM components to follow this can be verbose and tiresome. This function suite may be used to handle all that boring guff automatically, and log the details of caught exceptions to boot!
The invoke_nothrow() functions can be used to wrap non-member entry point functions, as illustrated in the following example (an extract from the adjunct library Pantheios.COM):
STDAPI DllRegisterServer_() { pantheios::log_NOTICE("DllRegisterServer()"); HRESULT hr = S_OK; #ifdef _MERGE_PROXYSTUB if(SUCCEEDED(hr)) { hr = PrxDllRegisterServer(); } #endif \/\* _MERGE_PROXYSTUB \*\/ if(SUCCEEDED(hr)) { hr = _Module.RegisterServer(true); } if(FAILED(hr)) { pantheios::log_ERROR( "Registration failed: ", pantheios::integer(hr, pantheios::fmt::fullHex) , ": ", winstl::error_desc_a(hr)); } else { // Translate all the other Pantheios loggers hr = ReregisterPantheiosEventSources(); } return hr; } STDAPI DllRegisterServer() { return pantheios::com::invoke_nothrow(DllRegisterServer_, "DllRegisterServer"); }
Any exceptions thrown in the implementation function, DllRegisterServer_()
will be caught by invoke_nothrow() and translated into the appropriate HRESULT
, and a corresponding log statement called.
The invoke_nothrow_method() functions can be used to wrap COM methods, as illustrated in the following example (an extract from Open-RJ.COM):
STDMETHODIMP Record::get_Count_(long *pVal) { pantheios::log_DEBUG("Record::Count"); return get_long_(pVal, &orj_record_t::numFields); } STDMETHODIMP Record::get_Count(long *pVal) { return pantheios::invoke_nothrow_method(this, &Record::get_Count_, pVal, "Record::Count"); }
Functions | |
template<typename R> | |
R | invoke_nothrow (R(stdcall *pfn)(), char const *functionName) |
Wraps a 0-parameter function in an exception-handler and logs any exceptions using Pantheios. | |
template<typename R, typename A0> | |
R | invoke_nothrow (R(stdcall *pfn)(A0), A0 a0, char const *functionName) |
Wraps a 1-parameter function in an exception-handler and logs any exceptions using Pantheios. | |
template<typename R, typename A0, typename A1> | |
R | invoke_nothrow (R(stdcall *pfn)(A0, A1), A0 a0, A1 a1, char const *functionName) |
Wraps a 2-parameter function in an exception-handler and logs any exceptions using Pantheios. | |
template<typename R, typename A0, typename A1, typename A2> | |
R | invoke_nothrow (R(stdcall *pfn)(A0, A1, A2), A0 a0, A1 a1, A2 a2, char const *functionName) |
Wraps a 3-parameter function in an exception-handler and logs any exceptions using Pantheios. | |
template<typename R, typename C, typename A0> | |
R | invoke_nothrow_method (C *pThis, R(stdcallC::*pfn)(A0), A0 a0, char const *functionName) |
Wraps a 1-parameter class member function in an exception-handler and logs any exceptions using Pantheios. | |
template<typename R, typename C, typename A0, typename A1> | |
R | invoke_nothrow_method (C *pThis, R(stdcallC::*pfn)(A0, A1), A0 a0, A1 a1, char const *functionName) |
Wraps a 2-parameter class member function in an exception-handler and logs any exceptions using Pantheios. | |
template<typename R, typename C, typename A0, typename A1, typename A2> | |
R | invoke_nothrow_method (C *pThis, R(stdcallC::*pfn)(A0, A1, A2), A0 a0, A1 a1, A2 a2, char const *functionName) |
Wraps a 3-parameter class member function in an exception-handler and logs any exceptions using Pantheios. | |
template<typename R, typename C, typename A0, typename A1, typename A2, typename A3> | |
R | invoke_nothrow_method (C *pThis, R(stdcallC::*pfn)(A0, A1, A2, A3), A0 a0, A1 a1, A2 a2, A3 a3, char const *functionName) |
Wraps a 4-parameter class member function in an exception-handler and logs any exceptions using Pantheios. | |
template<typename R, typename C, typename A0, typename A1, typename A2, typename A3, typename A4> | |
R | invoke_nothrow_method (C *pThis, R(stdcallC::*pfn)(A0, A1, A2, A3, A4), A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, char const *functionName) |
Wraps a 5-parameter class member function in an exception-handler and logs any exceptions using Pantheios. |
|
Wraps a 3-parameter function in an exception-handler and logs any exceptions using Pantheios.
|
|
Wraps a 2-parameter function in an exception-handler and logs any exceptions using Pantheios.
|
|
Wraps a 1-parameter function in an exception-handler and logs any exceptions using Pantheios.
|
|
Wraps a 0-parameter function in an exception-handler and logs any exceptions using Pantheios.
|
|
Wraps a 5-parameter class member function in an exception-handler and logs any exceptions using Pantheios.
|
|
Wraps a 4-parameter class member function in an exception-handler and logs any exceptions using Pantheios.
|
|
Wraps a 3-parameter class member function in an exception-handler and logs any exceptions using Pantheios.
|
|
Wraps a 2-parameter class member function in an exception-handler and logs any exceptions using Pantheios.
|
|
Wraps a 1-parameter class member function in an exception-handler and logs any exceptions using Pantheios.
|
|
|
pantheios Library documentation © Matthew Wilson, 2006 |
|