MapleTrapError
trap a Maple error in external code
Calling Sequence
Parameters
Description
Examples
MapleTrapError(kv, f, data, err)
kv
-
kernel handle of type MKernelVector
f
C function pointer
data
pointer to any data
err
boolean flag set to true if an error occurs executing f
This function can be used in external code with OpenMaple or define_external.
MapleTrapError attempts to execute the C function f(data). If a Maple error is raised at any time during execution of f, the function returns immediately after setting err to TRUE.
This function can be used in OpenMaple to abort function calls when MapleRaiseError is invoked.
#include "maplec.h"
typedef struct {
MKernelVector kv;
ALGEB *args;
} tryGuessArgs;
void *tryGuess( void *data )
{
return (void*)MyGuessInput(((tryGuessArgs*)data)->kv,
((tryGuessArgs*)data)->args);
}
ALGEB M_DECL MyGuessInput2( MKernelVector kv, ALGEB *args )
M_BOOL errorflag;
ALGEB result;
tryGuessArgs a;
a.kv = kv;
a.args = args;
result = (ALGEB)MapleTrapError(kv,tryGuess,&a,&errorflag);
if( errorflag ) {
result = EvalMapleStatement(kv,"lasterror:");
MapleALGEB_Printf(kv,"Caught error: %an",result);
return( ToMapleBoolean(kv,FALSE) );
else {
return( result );
Execute the external function from Maple.
with⁡ExternalCalling:
dll≔ExternalLibraryName⁡HelpExamples:
err≔DefineExternal⁡MyGuessInput2,dll:
err⁡2.2,2.2
Caught error: "one argument expected"
false
err⁡0,0
Caught error: "integer expected for M_INT parameter"
err⁡0
Caught error: ["%1 is too small", 0]
err⁡1
true
See Also
CustomWrapper
define_external
error
OpenMaple
OpenMaple/C/API
OpenMaple/C/Examples
traperror(deprecated)
Download Help Document