MapleTrapError - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

MapleTrapError

trap a Maple error in external code

 Calling Sequence MapleTrapError(kv, f, data, err)

Parameters

 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

Description

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

Examples

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

 > $\mathrm{with}\left(\mathrm{ExternalCalling}\right):$
 > $\mathrm{dll}≔\mathrm{ExternalLibraryName}\left("HelpExamples"\right):$
 > $\mathrm{err}≔\mathrm{DefineExternal}\left("MyGuessInput2",\mathrm{dll}\right):$
 > $\mathrm{err}\left(2.2,2.2\right)$
 Caught error: "one argument expected"
 ${\mathrm{false}}$ (1)
 > $\mathrm{err}\left(\left[0,0\right]\right)$
 Caught error: "integer expected for M_INT parameter"
 ${\mathrm{false}}$ (2)
 > $\mathrm{err}\left(0\right)$
 Caught error: ["%1 is too small", 0]
 ${\mathrm{false}}$ (3)
 > $\mathrm{err}\left(1\right)$
 ${\mathrm{true}}$ (4)