Protecting COM Interfaces from Exceptions

I have several dozen objects opened through COM interfaces, each of which has many methods, just a few hundred methods. These interfaces push business objects from my application into the script engine.

I was tasked with protecting each of these methods from exceptions that were thrown (in order to catch them and return an error using the COM function Error()By the way, I can’t find the documentation, because it’s not possible for Google) As far as I know, this requires adding try / catch around the gut of each of these methods. The catch blocks will be the same or identical for each of these hundreds of methods that smell like a problem (pretty much violate the DRY principle), but I can’t think of any way to avoid changing each method. As far as I can tell, these methods call COM directly, with no intermediate code that I can hook in to catch exceptions. My best idea is to make a macro for the catch block, but it has its own smell code. Can anyone come up with a better approach?

By the way, my exception applications do not come from std :: exception, so if there is some kind of COM method that automatically handles standard exceptions, this will not help. And I, unfortunately, cannot change existing exceptions to get from std :: exception.

+3
source share
4 answers

The most reliable C ++ way is to use macros here. I am ready to accept downvotes for this, but we have used this solution for many years and still have not seen any serious problems.

"begin method" IErrorInfo try { "end method" } catch . - , , , .

, , , , .

+3

. ++ SEH COM-. HRESULT. ISupportsErrorInfo IErrorInfo, . CLR .

Error(), , , ATL CComCoClass:: Error(). , IErrorInfo.

try/catch, , COM . COM, ++, . , , . , , , , , , .

factory, , . try/catch. , , , , .

+3

Comet - .

0

, COM- __stdcall , COM , "" COM--, COM- QueryInterface. COM- COM-, vtable thunk, vtable try/catch.

, , COM- .

0

Source: https://habr.com/ru/post/1743056/


All Articles