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 may want to also consider catching things like System.OutOfMemoryException and other exceptions that are the result of HRESULTs returned from COM objects. Not all failed HRESULTs result in COMException.
For most of the MAPI errors I've seen, the error codes don't vary from what's declared in the standard C MAPI header files, so I think the switch statement would be fine. In other words, that method shouldn't be any less compatible than a C-written MAPI client application.
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.
User contributions licensed under CC BY-SA 3.0