raise a Maple error in external code - Maple Help

Online Help

All Products    Maple    MapleSim

Home : Support : Online Help : Programming : OpenMaple : C Application Programming Interface : Evaluation and Error Handling : OpenMaple/C/MapleRaiseError

MapleRaiseError - raise a Maple error in external code

MapleRaiseError1 - raise a Maple error in external code

MapleRaiseError2 - raise a Maple error in external code

Calling Sequence

MapleRaiseError(kv, msg)

MapleRaiseError1(kv, msg, arg1)

MapleRaiseError2(kv, msg, arg1, arg2)




kernel handle of type MKernelVector



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.





Error, (in err) one argument expected


Error, (in err) integer expected for M_INT parameter


Error, (in err) -1 is too small


Error, (in err) 99 is too big




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,



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

Was this information helpful?

Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam