1. Isidro Reina Monsó
  2. PowerBuilder
  3. Friday, 7 August 2020 07:11 AM UTC

Hi.

I wrote this simple function in PB for testing:

public function long uof_square (long al_arg) throws exception;

exception e
e = create exception
e.Text = "test"

throw e

return al_arg * al_arg
end function

As you can see, it will always throw an exception.

I'm trying to invoke that function from a C++ application using PBNI. My goal is to capture the exception e in my C++ code to access its information. I'm using the code that you can see in the examples in the PBNI Manual:

...

    // Call the function

      try
    {
        session->InvokeObjectFunction(pbobj, mid, &ci);

        // Was PB exception thrown?
        if (session->HasExceptionThrown())
        {
            fprintf(stdout, "Exception!!");
            // Handle PB exception
            session->ClearException();
            return 1;
        }
    }
    catch (...)
    {
        // Handle C++ exception
    }

...

However, when I do that, in the InvokeObjectFunction() call I get a message telling me that the exception has not been handled. If I capture the exception in my PB code, either with a try-catch or by writing in the systemerror event of the application, I don't get the message, but HasExceptionThrown() returns 0, and the exception isn't available from my C++ code.

Am I doing something wrong?

If not, what's the point of HasExceptionThrown() if the exception will never be able to reach the C++ code?

Isidro Reina Monsó Accepted Answer Pending Moderation
  1. Friday, 14 August 2020 06:02 AM UTC
  2. PowerBuilder
  3. # 1

For anyone having the same problem that me:

I have found that InvokeObjectFunction() must be inside a scope defined by PushLocalFrame() and PopLocalFrame().

That way it works and HasExceptionThrown()can detect the exception.

Comment
  1. Miguel Leeuwe
  2. Friday, 14 August 2020 08:48 AM UTC
Thanks for sharing!
  1. Helpful
  1. John Fauss
  2. Friday, 14 August 2020 13:21 PM UTC
Glad to hear you found a solution, Isidro! Congratulations!
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Friday, 7 August 2020 14:20 PM UTC
  2. PowerBuilder
  3. # 2

Has your C++ application performed all of the PBNI initialization that appears to be needed in order to be able to access objects and invoke methods in PB through the PB Virtual Machine (PBVM)? I've only dabbled a little in PBNI and I've not attempted anything close to the level of sophistication you are attempting, but a scan of the PBNI documentation indicates that there are several steps your C++ application has to perform in order to be able to interface with PB object classes and methods.

https://docs.appeon.com/pb2019r2/native_interface_programmers_guide_and_reference/ch05s02.html

HTH, John

Comment
  1. Isidro Reina Monsó
  2. Monday, 10 August 2020 05:46 AM UTC
Hi John.



Yes, the PBVM is running and I can invoke methods.

In my example, if I remove the throw statement, I get the correct result: the square of the number. And that is only an example, I have run a lot of more sophisticated functions through PBNI. It's just the exceptions the ones aren't working for me.
  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.