Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

COM interface always masking exception message with "catastrophic failure"

I have a Delphi ActiveX project with 4 interfaces. Two of them have AutoComObject factories for their CoClasses. All the methods of the interfaces are declared with safecalls. In the interfaces with the factories, if a exception is thrown in any method, the caller receives an EOleException with the exception message from the original exception in the activex. But in the other two interfaces any exception gets masked as EOleException with the message masked to "Catastrophic Failure".

Anyone knows why this is happening, and how to make the original exception message not get masked?

like image 772
dmd_anfini Avatar asked Oct 16 '13 20:10

dmd_anfini


1 Answers

If an unhandled exception escapes a safecall method of a class, TObject.SafeCallException() is called to convert the exception into an HRESULT error code, which is then returned by COM to the caller. By default, TObject.SafeCallException() always returns E_UNEXPECTED ($8000FFFF). A class can override SafeCallException() to return a more meaningful HRESULT. TComObject and TAutoIntfObject do exactly that, for instance (they also call SetErrorInfo() to set detailed information about the exception, which the caller can retrieve using GetErrorInfo() if desired). So it sounds like your two AutoComObject-based objects have a SafeCallException() implementation, and your other two objects do not.

like image 145
Remy Lebeau Avatar answered Sep 20 '22 01:09

Remy Lebeau