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.
source
share