ErrorRaiseMethod

Applies to:Fast Math Parser
Class:uCalc.Callback
Raises an error in a uCalc.Callback function
Syntax
ErrorRaise(ErrNumber)
Parameters
ErrNumber
Index number of error to raise
Returns
Type: Int32
Remarks
Your callback can raise an error by calling this funciton with one of the values of the ErrorNumberEnum enumerator. End-user function definitions can also raise an error by calling Error() . The return value is determined by error handlers that you may have added. ErrorAbort (value of 0) is returned by default if there are no error handlers.
Example 1: Raises an error in a callback

Sub ErrRaiseTestCB(ByVal ExprPartPtr As IntPtr)
   Dim ExprPart As New uCalc.Callback(ExprPartPtr)
   if ExprPart.Arg(1) = 123 Then ExprPart.ErrorRaise(ErrorNumberEnum.Err_Unrecognized_Command)
   ExprPart.ReturnDbl(ExprPart.Arg(1))
End Sub

Sub ErrRaiseTest()
   uc.DefineFunction("ErrRaiseTest(Value)", uc.PinAddr(AddressOf ErrRaiseTestCB))
   Console.WriteLine(uc.EvalStr("ErrRaiseTest(111)")) ' Returns 111
   Console.WriteLine(uc.EvalStr("ErrRaiseTest(123)")) ' Returns "Unrecognized command": ' Our callback arbitrarily raises an error for 123
End Sub

          

static void ErrRaiseTestCB(IntPtr ExprPartPtr) {
   var ExprPart = New uCalc.Callback(ExprPartPtr);
   if (ExprPart.Arg(1) == 123) ExprPart.ErrorRaise(ErrorNumberEnum.Err_Unrecognized_Command);
   ExprPart.Return(ExprPart.Arg(1));
}

static void ErrRaiseTest() {
   uc.DefineFunction("ErrRaiseTest(Value)", uc.PinAddr(ErrRaiseTestCB));
   Console.WriteLine(uc.EvalStr("ErrRaiseTest(111)")); // Returns 111;
   Console.WriteLine(uc.EvalStr("ErrRaiseTest(123)")); // Returns "Unrecognized command"; // Our callback arbitrarily raises an error for 123
}

          

procedure ErrRaiseTestCB(ExprPartPtr: System.Pointer);
begin
   
//var ExprPart: uCalc.CreateCallback(ExprPartPtr);
   if ExprPart.Arg(1) = 123 Then ExprPart.ErrorRaise(ErrorNumberEnum.Err_Unrecognized_Command);
   ExprPart.Return(ExprPart.Arg(1));
End;

procedure ErrRaiseTest();
begin
   
   uc.DefineFunction('ErrRaiseTest(Value)', ErrRaiseTestCB);
   WriteLn(uc.EvalStr('ErrRaiseTest(111)')); // Returns 111;
   WriteLn(uc.EvalStr('ErrRaiseTest(123)')); // Returns 'Unrecognized command'; // Our callback arbitrarily raises an error for 123
End;

          

void _stdcall ErrRaiseTestCB(uCalcPtr ExprPartPtr) {
   auto ExprPart = uCalc::Callback(ExprPartPtr);
   if (ExprPart.Arg(1) == 123) ExprPart.ErrorRaise(ErrorNumberEnum::Err_Unrecognized_Command);
   ExprPart.Return(ExprPart.Arg(1));
}

void ErrRaiseTest() {
   uc.DefineFunction("ErrRaiseTest(Value)", ErrRaiseTestCB);
   cout << uc.EvalStr("ErrRaiseTest(111)") << endl; // Returns 111;
   cout << uc.EvalStr("ErrRaiseTest(123)") << endl; // Returns "Unrecognized command"; // Our callback arbitrarily raises an error for 123
}

          

static void ErrRaiseTestCB(uCalcPtr ExprPartPtr) {
   auto ExprPart = uCalc::Callback(ExprPartPtr);
   if (ExprPart.Arg(1) == 123) ExprPart.ErrorRaise(ErrorNumberEnum::Err_Unrecognized_Command);
   ExprPart.Return(ExprPart.Arg(1));
}

static void ErrRaiseTest() {
   uc.DefineFunction("ErrRaiseTest(Value)", ucPinAddr(ErrRaiseTestCB));
   Console::WriteLine(uc.EvalStr("ErrRaiseTest(111)")); // Returns 111;
   Console::WriteLine(uc.EvalStr("ErrRaiseTest(123)")); // Returns "Unrecognized command"; // Our callback arbitrarily raises an error for 123
}

          
DLL import code
<DllImport(uCalcDLL, CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Cdecl, EntryPoint:="ErrorRaise")> _

Private Function ErrorRaise__(ByVal ExprPartHandle As IntPtr,ByVal ErrNumber As ErrorNumberEnum) As  Int32
End Function
            
[DllImport(uCalcDLL, CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl, EntryPoint="ErrorRaise")]

protected static extern  Int32 ErrorRaise_(IntPtr ExprPartHandle,ErrorNumberEnum ErrNumber);
            
{DLLImport}function ErrorRaise__(ExprPartHandle: System.Pointer;ErrNumber: ErrorNumberEnum):  Int32; cdecl; external uCalcDLL name 'ErrorRaise';

            
typedef  int32_t (* __ErrorRaise)(void *ExprPartHandle, ErrorNumberEnum ErrNumber); 

            
[DllImport(uCalcLib, CharSet=CharSet::Ansi, CallingConvention=CallingConvention::Cdecl, EntryPoint = "ErrorRaise")]

static Int32 ErrorRaise_(void *  ExprPartHandle, ErrorNumberEnum ErrNumber);
            
Prev | Next