0
Votes
Undo
  1. Ashutosh Varshney
  2. PowerBuilder
  3. Wednesday, 13 December 2017

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
0
Votes
Undo

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
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. Ashutosh Varshney
  2. Wednesday, 13 December 2017
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. Michael Kramer
  2. Thursday, 14 December 2017
That works. Thanks Mike!

  1. Ashutosh Varshney
  2. Thursday, 14 December 2017
There are no comments made yet.
  1. Wednesday, 13 December 2017
  2. PowerBuilder
  3. # Permalink
Shenn Sellers Accepted Answer Pending Moderation
0
Votes
Undo

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
Thanks Shenn. I was able to catch it using RuntimeError exception.

  1. Ashutosh Varshney
  2. Thursday, 14 December 2017
There are no comments made yet.
  1. Wednesday, 13 December 2017
  2. PowerBuilder
  3. # 1
  • Page :
  • 1


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