trap 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/MapleTrapError

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:");

        MaplePrintf(kv,"Caught error: %sn",MapleToString(kv,result));

        return( ToMapleBoolean(kv,FALSE) );

    }

    else {

        return( result );

    }

    }

Execute the external function from Maple.

withExternalCalling:

dll:=ExternalLibraryNameHelpExamples:

err:=DefineExternalMyGuessInput2,dll:

err2.2,2.2

Caught error: one argument expected

false

(1)

err0,0

Caught error: integer expected for M_INT parameter

false

(2)

err0

Caught error: %1 is too small

false

(3)

err1

true

(4)

See Also

CustomWrapper, define_external, error, OpenMaple, OpenMaple/C/API, OpenMaple/C/Examples, traperror(deprecated)


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