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?
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.