0
Votes
Undo
  1. Ashutosh Varshney
  2. PowerBuilder
  3. Wednesday, 13 December 2017 16:03 PM UTC

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.

Accepted Answer
Michael Kramer Accepted Answer Pending Moderation
  1. Wednesday, 13 December 2017 17:34 PM UTC
  2. PowerBuilder
  3. # Permalink

One solution is to use TRY-CATCH exception handling.

You can provide a user-friendly error message and disable functionality that requires the OCX.

Comment
  1. Ashutosh Varshney
  2. Wednesday, 13 December 2017 19:50 PM UTC
Thanks Mike. But I already have it in a Try...Catch construct:



// 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

  1. Helpful
  1. Michael Kramer
  2. Thursday, 14 December 2017 09:44 AM UTC
Hi Ashutosh, Unfortunately your code catches the wrong type of exception.





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



  1. Helpful
  1. Ashutosh Varshney
  2. Thursday, 14 December 2017 14:22 PM UTC
That works. Thanks Mike!

  1. Helpful
There are no comments made yet.
Shenn Sellers Accepted Answer Pending Moderation
  1. Wednesday, 13 December 2017 20:06 PM UTC
  2. PowerBuilder
  3. # 1

Does the OCX create any Registry entries?  I use Outlook Redemption and check the Registry to see if it is installed.  If I don't find it, I disable the features that use it.  All registered COM class objects are listed under HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\.

Comment
  1. Ashutosh Varshney
  2. Thursday, 14 December 2017 14:24 PM UTC
Thanks Shenn. I was able to catch it using RuntimeError exception.

  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.