PHB_ITEM hb_errRT_SubstParams( const char * szSubSystem, HB_ERRCODE errGenCode, HB_ERRCODE errSubCode, const char * szDescription, const char * szOperation ) { PHB_ITEM pRetVal; PHB_ITEM pError; PHB_ITEM pArray; HB_TRACE( HB_TR_DEBUG, ( "hb_errRT_SubstParams()" ) ); pError = hb_errRT_New_Subst( ES_ERROR, szSubSystem ? szSubSystem : HB_ERR_SS_BASE, errGenCode, errSubCode, szDescription, szOperation, 0, EF_NONE ); pArray = hb_arrayBaseParams(); /* Assign the new array to the object data item. */ hb_errPutArgsArray( pError, pArray ); /* Release the Array. */ hb_itemRelease( pArray ); /* Ok, launch... */ pRetVal = hb_errLaunchSubst( pError ); hb_itemRelease( pError ); return pRetVal; }
PHB_ITEM hb_errRT_BASE_Subst( HB_ERRCODE errGenCode, HB_ERRCODE errSubCode, const char * szDescription, const char * szOperation, HB_ULONG ulArgCount, ... ) { PHB_ITEM pRetVal; PHB_ITEM pError; PHB_ITEM pArray; va_list va; HB_ULONG ulArgPos; pError = hb_errRT_New_Subst( ES_ERROR, HB_ERR_SS_BASE, errGenCode, errSubCode, szDescription, szOperation, 0, EF_NONE ); /* Build the array from the passed arguments. */ switch( ulArgCount ) { case 0: pArray = NULL; break; case HB_ERR_ARGS_BASEPARAMS: pArray = hb_pcount() ? hb_arrayBaseParams() : NULL; break; case HB_ERR_ARGS_SELFPARAMS: pArray = hb_arraySelfParams(); break; default: pArray = hb_itemArrayNew( ulArgCount ); va_start( va, ulArgCount ); for( ulArgPos = 1; ulArgPos <= ulArgCount; ulArgPos++ ) { PHB_ITEM pArg = va_arg( va, PHB_ITEM ); if( pArg ) hb_itemArrayPut( pArray, ulArgPos, pArg ); } va_end( va ); } if( pArray ) { /* Assign the new array to the object data item. */ hb_errPutArgsArray( pError, pArray ); /* Release the Array. */ hb_itemRelease( pArray ); } /* Ok, launch... */ pRetVal = hb_errLaunchSubst( pError ); hb_errRelease( pError ); return pRetVal; }
/* Harbour default math error handling routine */ static int hb_matherr( HB_MATH_EXCEPTION * pexc ) { int mode = hb_mathGetErrMode(); int iRet = 1; HB_TRACE( HB_TR_DEBUG, ( "hb_matherr(%p)", ( void * ) pexc ) ); if( pexc == NULL || pexc->handled != 0 ) { /* error already handled by other handlers ! */ return 1; } if( mode == HB_MATH_ERRMODE_USER || mode == HB_MATH_ERRMODE_USERDEFAULT || mode == HB_MATH_ERRMODE_USERCDEFAULT ) { PHB_ITEM pArg1, pArg2, pError; PHB_ITEM pMatherrResult; /* create an error object */ /* NOTE: In case of HB_MATH_ERRMODE_USER[C]DEFAULT, I am setting both EF_CANSUBSTITUTE and EF_CANDEFAULT to .T. here. This is forbidden according to the original Cl*pper docs, but I think this reflects the situation best here: The error handler can either substitute the erroneous value (by returning a numeric value) or choose the default error handling (by returning .F., as usual) [martin vogel] */ pError = hb_errRT_New_Subst( ES_ERROR, "MATH", EG_NUMERR, pexc->type, pexc->error, pexc->funcname, 0, EF_CANSUBSTITUTE | ( mode == HB_MATH_ERRMODE_USER ? 0 : EF_CANDEFAULT ) ); /* Assign the new array to the object data item. */ /* NOTE: Unfortunately, we cannot decide whether one or two parameters have been used when the math function has been called, so we always take two */ pArg1 = hb_itemPutND( NULL, pexc->arg1 ); pArg2 = hb_itemPutND( NULL, pexc->arg2 ); hb_errPutArgs( pError, 2, pArg1, pArg2 ); hb_itemRelease( pArg1 ); hb_itemRelease( pArg2 ); /* launch error codeblock */ pMatherrResult = hb_errLaunchSubst( pError ); hb_errRelease( pError ); if( pMatherrResult ) { if( HB_IS_NUMERIC( pMatherrResult ) ) { pexc->retval = hb_itemGetND( pMatherrResult ); hb_itemGetNLen( pMatherrResult, &pexc->retvalwidth, &pexc->retvaldec ); pexc->handled = 1; } hb_itemRelease( pMatherrResult ); } } /* math exception not handled by Harbour error routine above ? */ if( pexc->handled == 0 ) { switch( mode ) { case HB_MATH_ERRMODE_USER: /* user failed to handle the math exception, so quit the app [yes, that's the meaning of this mode !!] */ iRet = 0; hb_vmRequestQuit(); break; case HB_MATH_ERRMODE_DEFAULT: case HB_MATH_ERRMODE_USERDEFAULT: /* return 1 to suppress C RTL error msgs, but leave error handling to the calling Harbour routine */ break; case HB_MATH_ERRMODE_CDEFAULT: case HB_MATH_ERRMODE_USERCDEFAULT: /* use the correction value supplied in pexc->retval */ pexc->handled = 1; break; } } return iRet; /* error handling successful */ }
/* throwing a CT-subsystem error with value substitution - function adapted from errorapi.c */ PHB_ITEM ct_error_subst( HB_USHORT uiSeverity, HB_ERRCODE errGenCode, HB_ERRCODE errSubCode, const char * szDescription, const char * szOperation, HB_ERRCODE errOsCode, HB_USHORT uiFlags, HB_ULONG ulArgCount, ... ) { PHB_ITEM pRetVal; PHB_ITEM pError; PHB_ITEM pArray; va_list va; HB_ULONG ulArgPos; HB_TRACE( HB_TR_DEBUG, ( "ct_error_subst(%hu, %d, %d, %s, %s, %d, %hu, %lu)", uiSeverity, errGenCode, errSubCode, szDescription, szOperation, errOsCode, uiFlags, ulArgCount ) ); pError = hb_errRT_New_Subst( uiSeverity, CT_SUBSYSTEM, errGenCode, errSubCode, szDescription, szOperation, errOsCode, uiFlags ); /* Build the array from the passed arguments. */ if( ulArgCount == 0 ) { pArray = NULL; } else if( ulArgCount == HB_ERR_ARGS_BASEPARAMS ) { if( hb_pcount() == 0 ) pArray = NULL; else pArray = hb_arrayBaseParams(); } else if( ulArgCount == HB_ERR_ARGS_SELFPARAMS ) { pArray = hb_arraySelfParams(); } else { pArray = hb_itemArrayNew( ulArgCount ); va_start( va, ulArgCount ); for( ulArgPos = 1; ulArgPos <= ulArgCount; ulArgPos++ ) { hb_itemArrayPut( pArray, ulArgPos, va_arg( va, PHB_ITEM ) ); } va_end( va ); } if( pArray ) { /* Assign the new array to the object data item. */ hb_vmPushSymbol( hb_dynsymGetSymbol( "_ARGS" ) ); hb_vmPush( pError ); hb_vmPush( pArray ); hb_vmSend( 1 ); /* Release the Array. */ hb_itemRelease( pArray ); } /* launch error codeblock */ pRetVal = hb_errLaunchSubst( pError ); hb_errRelease( pError ); return pRetVal; }