0

When Interop with Outlook, I need to handle several exceptions, they are all COMException with the same HResult, the only difference is in their Message property.

I have to tell them from each other by examining the Message property, but such code is asking for trouble.

if (ex.Message.Contains("is bigger than the server allows")) //??? 

So what is the proper way to handle exception when examining the type of exception and the HResult property won't work?

enter image description here

enter image description here

kennyzx
  • 12,845
  • 6
  • 39
  • 83
  • That is the famous E_FAIL. They are *vexing* exceptions. If you handle them then you **must** take corrective action so they can't be raised again. So, roughly, the dialog requires you to run UI automation code that finds the dialog and closes it. Even though it is surely there for a good reason and the user is interacting with it. And the attachment error requires you to run the installer for a better, larger version of the server. Even though that is surely guaranteed to be what the server admin does *not* want you to do. You can't handle these truths. – Hans Passant Jun 06 '17 at 08:25

1 Answers1

0

checking the message was what we did in similar project. It is ugly but works. To get more comfort, you can look for some outlook specification to get full list of error messages. What do you mean exactly by 'asking for trouble'? the code not robust?

Bing Wang
  • 1,548
  • 1
  • 8
  • 7
  • The biggest problem is, error messages are localized on customer's device. In this case I expect error codes which are well defined integers. – kennyzx Jun 06 '17 at 04:01