1. Aron Cox
  2. PowerBuilder
  3. Wednesday, 15 January 2020 14:32 PM UTC

Powerbuilder 2017 R2.

I want to catch an OLERuntimeException when my PowerBuilder code tries to call a function on an ActiveX control that hasn't been installed on the machine in question.

I put a TRY CATCH around the call, and in the PB IDE an OLERunTimeException error message is displayed, but in a build the message in my CATCH statement is displayed. I can live with that.

At that point I want to return something like FALSE to the caller and carry on, but then, as it says in the help file, the error bubbles up to the System Error event.

Help File:

"The exception then continues to unwind the call stack to any outer nested try-catch blocks. If there are no outer nested blocks, the SystemError event on the Application object is fired." 

How do I stop the error once I have dome whatever I want in the very first Catch statement? Maybe I don't want it to bubble up and I just want to return some kind of failure code to the caller.

I feel like I must be missing something really simple, i do this all the time in .NET code, by literally not rethrowing the error???

Accepted Answer
Aron Cox Accepted Answer Pending Moderation
  1. Thursday, 16 January 2020 09:34 AM UTC
  2. PowerBuilder
  3. # Permalink

Ahah, found it.

Adding action = ExceptionIgnore! to the Error and ExternalException events allows the TRY..CATCH to do it's thing without bubbling up.

If I'm running from the IDE I do get an extra OLERuntimeException error message and clicking on the Ignore button allows the code to carry on, from a build it all works as I'd like :)

For the actual solution I've wrapped the ExceptionIgnore! code with a boolean so I can turn on and off ignoring as I like, because sometimes I want the error message to appear and sometimes I don't.

Comment
There are no comments made yet.
Arthur Hefti Accepted Answer Pending Moderation
  1. Thursday, 16 January 2020 05:27 AM UTC
  2. PowerBuilder
  3. # 1

How about setting an instance variable whether the control is available or not.

We use an external text control ActiveX and access in the constructor properties of it, when it's missing an exception is thrown. I see 2 options

1. Use the error event on the ActiveX and set action = ExceptionIgnore! when it's missing and set the instance variable

2. When I put a TRY .. CATCH block in the constructor event around it I can set a variable that the control is not available. I have no call of the system error event after this.

TRY
  This.Object.SomeProperty = xxxx
CATCH (OleRuntimeError e)
 MessageBox( "Error", e.Text ) // Or whatever you need
 ib_NoOCX = TRUE
END TRY

Regards
Arthur

 

 

 

Comment
  1. Aron Cox
  2. Friday, 17 January 2020 03:51 AM UTC
Yes using an instance variable to store the availability of the control is a good idea. In my case I just wanted to show the controls current state in the Help | About screen, but ideally I would check at startup, inform the user and then disable any functionality that requires the control.
  1. Helpful
There are no comments made yet.
Arthur Hefti Accepted Answer Pending Moderation
  1. Wednesday, 15 January 2020 15:32 PM UTC
  2. PowerBuilder
  3. # 2

Hi 

check out SetAutomationPointer. There you can handle the events of the ole object errors.

https://docs.appeon.com/appeon_online_help/pb2017r2/application_techniques/ch19s05.html#d0e14524

Regards
Arthur

Comment
  1. Aron Cox
  2. Thursday, 16 January 2020 04:33 AM UTC
Hi thanks for the reply. I don't think it has anything to do with SetAutomationPointer as that appears to be an issue when you have a non-visual ActiveX control that you want to handle events on.



In my case I have an actual Visual ActiveX control, using Microsoft Chart Control for .NET, so I have direct access to the events.



  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.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.