Based on this SO answer: Catching COMException specific Error Code, I’d like to know, to properly handle COMExceptions across OSs and multiple versions of OL, if I need to only look at a specific portion of the exception. For example,
private const uint HRESULT_OPERATIONABORTED = 0x80004004;
// ...
try {
// something that could throw COMExceptions
} catch (System.Runtime.InteropServices.COMException e) {
switch ((uint)e.ErrorCode) {
case HRESULT_OPERATIONABORTED:
break;
default:
break;
}
}
Is this sufficiently cross-platform, or is it necessary to consider only a part of the error code?
EDIT – Just to clarify, my exact question is whether comparing (uint)e.ErrorCode to 0x80004004 is too specific (that is to say, whether or not I always get 0x80004004 for this particular error, regardless of OS/OL), or if this is the proper way to do things.
You have little to fear as far as cross-platform compat goes, COM only runs on Windows. Similarly, the error code is a well defined one. You can look up the standard COM error codes in the WinError.h SDK header file. It is E_ABORT. I’d recommend you actually use that identifier.
You’ll find this header in c:\program files\microsoft sdks\windows\v6.0\include. It is v7.0 for VS2010.