Synopsis

(macro) void pdx_EC(func)

Purpose

Invoke a PDElib function with error check.

Description

This macro invokes function and stores the return code in a local variable named rc. If the return code is not equal to PDX_NOERR, a "goto cleanup" is executed. This macro requires that the calling code defines a local variable named rc as type PDX_MSGT and a label named cleanup which contains code to be executed when an error is detected. The following example shows how pdx_EC can be used with the pdx_Return macro to simplify error handling. Note that no semi-colon is placed after the pdx_EC statement (pdx_EC must enclose the check in curly braces to prevent problems with dangling else statements). .nf PDX_MSGT rc = PDX_NOERR, rc2 = PDX_NOERR; . . ent1 = NULL; ent2 = NULL; . . pdx_EC( mda_LockEntity (MDA_NOOPT, db_ptr1, &ent1) ) pdx_EC( mda_LockEntity (MDA_NOOPT, db_ptr2, &ent2) ) . . cleanup: if ( ent1 != NULL ) rc2 |= mda_UnlockEntity (MDA_NOOPT, db_ptr1); if ( ent2 != NULL ) rc2 |= mda_UnlockEntity (MDA_NOOPT, db_ptr2); pdx_Return(); .fi The first pdx_EC() statement above is equivalent to: .nf { if ((rc = mda_LockEntity (MDA_NOOPT, db_ptr1, &ent1)) != PDX_NOERR) goto cleanup; } .fi

And the pdx_Return() statement is equivalent to: .nf if (rc2 != PDX_NOERR) return (mpm_SetError (MPM_NOOPT, PDX_CLEANUP_ERR, MPM_ERROR, __FILE__, __LINE__)); return (rc); .fi

Input

func

PDElib function to be invoked, assumed to return a type of PDX_MSGT