Jade API - C++ Exception Handling

For questions and postings not covered by the other forums
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Jade API - C++ Exception Handling

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:26 pm

by Kevin Saul >> Mon, 9 Mar 2009 20:50:50 GMT

Hi All,

When referring to the "Handling Nested C++ Exceptions" section in the Object Manager documentation it provides the example shown below.

However, when I look at the Jade API header files provided, I cannot find jomGetExceptionUnwindState or JomException.

Can anyone shed any light on why these are missing?
Can anyone provide any examples on how exceptions should be caught in C++ in a similar manner?

While I realize there are functions for arming Jade exception handlers, I would like to simply handle an exception in C++ using a try/catch statement.

Cheers,
Kevin

Example from Jade documentation:

ClassA::~ClassA
{
try
{
int result= jomDeleteObject(...);
}
catch (JomException &e)
{
// the jomDeleteObject caused an exception
bool unwinding;
jomGetExceptionUnwindState(0, &unwinding, 0);
if (!unwinding) // it is safe to raise the exception
throw;
else
log("jomDeleteObject failed : exception type = %d" e.errorNumber);
endif;
}
};

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Jade API - C++ Exception Handling

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:26 pm

by Jade Support >> Thu, 12 Mar 2009 23:54:31 GMT

In JADE 6.2 these function prototypes weren't in the headers (they should have been). They are in JADE 6.3.

For JADE 6.2 you can add the values manually to the jomcalls.h file as below:

1. After the...

JOM_EXPORT int JOMAPI jomDeregisterTerminationCallBack(const DskHandle* pHandle,
const JadeTerminationCallBack cb,
const void * pParam,
TerminationCallBackType,
UInt32 lineNo);

.....declaration add:

JOM_EXPORT int JOMAPI jomGetExceptionUnwindState(const DskHandle * pHandle, bool * pUnwinding, LineNumber lineNo);

2. After the "typedef int (JOMAPI* JomGetAddressSpaceId)(const DskHandle *, int *);" line add:

typedef int (JOMAPI *JomGetExceptionUnwindState)(const DskHandle * pHandle, bool * pUnwinding, LineNumber lineNo);

3. Save the file.

Regards,
Jade Support.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Jade API - C++ Exception Handling

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:26 pm

by Kevin Saul >> Sun, 15 Mar 2009 2:23:28 GMT

Thanks for the definitions supplied.
I had to tweak them slightly, replacing LineNumber with UInt32, as LineNumber is not defined in the 6.2 headers.

The definition for JomException is also missing, can you please supply this as well?

Cheers,
Kevin

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Jade API - C++ Exception Handling

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:26 pm

by Jade Support >> Thu, 19 Mar 2009 0:13:11 GMT

Using jomGetExceptionUnwindState and the JomException class is not appropriate for catching unhandled JADE exceptions.

To achieve the intended aim, a global exception handler should be armed, using the "jomArmExceptionHandler" API, before calling any JADE methods.

The exception handler can be written in C++, but will need an external method definition for it in the schema.

Within the exception handler method, the second parameter (pExceptionParam) can be used to retrieve the OID of the exception object. This OID can be used with jomGetProperty to retrieve the error code, and jomSendMsg to call the "errorObject" method to retrieve the error object, etc.

The third parameter (pResultParam) is for the return value. To cancel all further processing and return a JOM_METHOD_ABORTED result to the outer C++ method, paramSetInteger should be used to set the value to E_ABORT_ACTION.

Using try/catch in the outer C++ method will not catch the JADE exception, because JADE exceptions are caught internally. A JOM_METHOD_ABORTED result is returned to the outer level rather than a C++ exception.

Thank you,
Jade Support.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Jade API - C++ Exception Handling

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:26 pm

by Kevin Saul >> Thu, 19 Mar 2009 22:15:02 GMT

Thank you, this has solved my problem.

I must admit, I hadn't thought of creating an external method as a global exception handler.

Cheers,
Kevin


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 30 guests