Borland C++ Builder provides the function
OleCheck(HRESULT Result);. Its description in the documentation is this:
OleCheck is used to wrap many COM routines, so that if that routine fails, users will have an opportunity to handle it in the resulting exception that is raised.
If ECode is a value less than zero, OleCheck raises an EOleSysError exception that specifies the error code.
What is the recommended function or idiom to use with Microsoft ATL for throwing an exception if a function returns a failed status value? I'd like to avoid mixing Borland and Microsoft libraries in code like this:
There's no such ready thing in ATL. The closest thing is
AtlThrow() which throws an exception (unconditionally), but the check is still up to you - you can look into how
AtlThrow() is used in ATL itself.
So IMO your best bet is to craft your own function - it will accept
HRESULT and call
AtlThrow() or some other exception-trowing construct for
HRESULTs that evalate to