Throw If Fails

I like to use this when writting sample code:

inline void Tif(HRESULT hResult) {

   if FAILED(hResult) {

      throw _com_error(hResult);

   }

}

inline void Tif(bool succeeded) {

   if (!succeeded) {

      DWORD lastError = GetLastError();

      throw win32_exception(lastError);

   }

}

inline void Tif(BOOL succeeded) {

   Tif(succeeded != FALSE); // And not == TRUE, thanks Mike!

}

 

The first exception type is defined in comdef.h and the second in win32_exception.h, in the std namespace.