MapleRaiseError
raise a Maple error in external code
MapleRaiseError1
MapleRaiseError2
Calling Sequence
Parameters
Description
Examples
MapleRaiseError(kv, msg)
MapleRaiseError1(kv, msg, arg1)
MapleRaiseError2(kv, msg, arg1, arg2)
kv
-
kernel handle of type MKernelVector
msg
error message
arg1, arg2
type ALGEB objects
These functions can be used in external code with OpenMaple or define_external.
These functions raise the Maple error described by msg, equivalent to the Maple command error(msg,arg1,arg2);.
If used as part of ExternalCalling, execution is returned back to Maple (or to the exception handler installed by a try command). If used as part of OpenMaple, the errorCallBack is invoked, and execution continues at the next statement. The OpenMaple behavior can be changed to interrupt computation at an error invoked by MapleRaiseError when the external function is launched via MapleTrapError.
The character string msg can contain wildcards of the form %N, where N is a non-zero integer. These wildcards are replaced by the extra argument, arg1 or arg2, before displaying the message. If %-N is specified, then the optional argument is displayed with the appropriate suffix, st, nd, rd, or th, appended. For example, consider the following command.
MapleRaiseError2(kv, "the %-1 argument, '%2', is not valid",
ToMapleInteger(i), args[i]);
This, if invoked, raises the error, "the 4th argument, 'foo', is not valid", assuming i=4, and args[i] is set to the Maple name, foo. For more information, see error. The only option not allowed is %0 since the function cannot determine the number of unparsed optional arguments.
#include "maplec.h"
ALGEB M_DECL MyGuessInput( MKernelVector kv, ALGEB *args )
{
M_INT n;
if( MapleNumArgs(kv,(ALGEB)args) != 1 )
MapleRaiseError(kv,"one argument expected");
n = MapleToM_INT(kv,args[1]);
if( n <= 0 )
MapleRaiseError1(kv,"%1 is too small",args[1]);
if( n > 1 )
MapleRaiseError1(kv,"%1 is too big",args[1]);
return( ToMapleBoolean(kv,TRUE) );
}
Execute the external function from Maple.
with⁡ExternalCalling:
dll≔ExternalLibraryName⁡HelpExamples:
err≔DefineExternal⁡MyGuessInput,dll:
err⁡
Error, (in err) one argument expected
err⁡0,0
Error, (in err) integer expected for M_INT parameter
err⁡−1
Error, (in err) -1 is too small
err⁡99
Error, (in err) 99 is too big
err⁡1
true
Note: Because the examples above were executed within Maple,
execution terminated when the first error was raised. This is
not the case when MapleRaiseError is called directly from an
OpenMaple program. Consider the following code executed after
starting OpenMaple.
ALGEB r = ToMapleExpressionSequence(kv,2,
ToMapleFloat(kv,2.2),ToMapleFloat(kv,2.2));
MyGuessInput(kv,(ALGEB*)r);
Since MapleRaiseError does not stop execution, the one call
produces three errors.
Error, one argument expected
Error, integer expected for M_INT parameter
Error, 2.20000000000000016 is too small
See Also
CustomWrapper
define_external
OpenMaple
OpenMaple/C/API
OpenMaple/C/Examples
Download Help Document