Hello,
I have a custom ocx control on a PB classic window which interacts with MS Office. Right now, if the ocx file has not been deployed or registered, the application simply crashes after displaying "Error calling external object function' error.
I want to be able check if the ocx is setup or not and let users continue to use my application but disable functions provided by that ocx. Any ideas how that can be done?
Thanks.
// Init op
Try
ole_1.Object.Init () // This statement generates Error calling external object function message
Catch (Exception e)
MessageBox ('Error', 'Init op failed.' )
End Try
Exception is the base class for checked exceptions
RuntimeError is the base class for unchecked exceptions
I would expect that the exceptions thrown by your call to Init( ) are either RuntimeError or OLERuntimeError (subclass of RuntimeError).
Try this:
TRY
OLE_1.Object.Init()
CATCH (RuntimeError exRuntime)
MessageBox('Error', exRuntime.GetMessage( ))
END TRY
OLE Automation usually throws OLERuntimeError exceptions that include additional information. Therefore, I often wrap each block of OLE Automation calls with below code to enrich the error message exposed to callers that may only catch the exception as RuntimeError.
TRY
// ... OLE Automation calls ...
CATCH (OLERuntimeError exOLE)
// Enrich error message
exOLE.SetMessage(exOLE.Description + '~r~n' + exOLE.GetMessage( ))
// Re-throw to expose enriched exception to caller
THROW exOLE
END TRY