trap a Maple error in external code - Maple Help

Online Help

All Products    Maple    MapleSim

Home : Support : Online Help : Programming : OpenMaple : VB Application Programming Interface : Evaluation and Error Handling : OpenMaple/VB/MapleTrapError

MapleTrapError - trap a Maple error in external code

Calling Sequence

MapleTrapError(kv, f, data, err)




kernel handle returned by StartMaple



function pointer



integer data



boolean flag set to True if an error occurs executing f



This function is part of the OpenMaple interface to Microsoft Visual Basic.


The MapleTrapError function attempts to execute the VB 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.


Use the GetProc and AddressOf commands to get the address of a VB function as shown in the example below.


This function can be used to abort function calls when MapleRaiseError is invoked.


dim global_kv as long

Public Function TestTrapErrorCB1(data As Long) As Long

    MapleRaiseError global_kv, "test"

    TestTrapErrorCB1 = data

End Function

Public Function TestTrapErrorCB2(data As Long) As Long

    TestTrapErrorCB2 = EvalMapleStatement(global_kv, "int(x,x):")

End Function

Public Sub TestTrapError(ByVal kv As Long)

    Dim errorflag As Long

    Dim data As Long

    global_kv = kv

    data = MapleTrapError(kv, GetProc(AddressOf TestTrapErrorCB1), _

              365, errorflag)

    If errorflag = 0 Then

        MsgBox "should have been an error (errorflag = 1)", _

              vbInformation, ""

    End If

    data = MapleTrapError(kv, GetProc(AddressOf TestTrapErrorCB2), _

              0, errorflag)

    If errorflag = 1 Then

        MsgBox "should NOT have been an error (errorflag = 0)", _

              vbInformation, """"

    End If

End Sub

See Also

error, OpenMaple, OpenMaple/VB/API, OpenMaple/VB/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