ErrorRaiseMessageMethod

Applies to:Fast Math Parser
Class:uCalc.Callback
Raises an error with a user-defined message in a uCalc.Callback function
Syntax
ErrorRaiseMessage(ErrMessage)
Parameters
ErrMessage
String
Text of custom error message to return
Returns
Type: Int32
Remarks
Your callback can raise a custom error message (one not listed as a ErrorNumberEnum enumerator) by simply passing the text of the message to this function.
Example 1: Raises an error in a callback

Sub ErrRaiseMsgTestCB(ByVal ExprPartPtr As IntPtr)
   Dim ExprPart As New uCalc.Callback(ExprPartPtr)
   if ExprPart.Arg(1) = 123 Then ExprPart.ErrorRaiseMessage("I do not like this value!")
   ExprPart.ReturnDbl(ExprPart.Arg(1))
End Sub

Sub ErrRaiseMsgTest()
   uc.DefineFunction("ErrRaiseMsgTest(Value)", uc.PinAddr(AddressOf ErrRaiseMsgTestCB))
   Console.WriteLine(uc.EvalStr("ErrRaiseMsgTest(111)")) ' Returns 111
   Console.WriteLine(uc.EvalStr("ErrRaiseMsgTest(123)")) ' Returns "I do not like this value!": ' Our callback arbitrarily raises an error for 123
End Sub

          

static void ErrRaiseMsgTestCB(IntPtr ExprPartPtr) {
   var ExprPart = New uCalc.Callback(ExprPartPtr);
   if (ExprPart.Arg(1) == 123) ExprPart.ErrorRaiseMessage("I do not like this value!");
   ExprPart.Return(ExprPart.Arg(1));
}

static void ErrRaiseMsgTest() {
   uc.DefineFunction("ErrRaiseMsgTest(Value)", uc.PinAddr(ErrRaiseMsgTestCB));
   Console.WriteLine(uc.EvalStr("ErrRaiseMsgTest(111)")); // Returns 111;
   Console.WriteLine(uc.EvalStr("ErrRaiseMsgTest(123)")); // Returns "I do not like this value!"; // Our callback arbitrarily raises an error for 123
}

          

procedure ErrRaiseMsgTestCB(ExprPartPtr: System.Pointer);
begin
   
//var ExprPart: uCalc.CreateCallback(ExprPartPtr);
   if ExprPart.Arg(1) = 123 Then ExprPart.ErrorRaiseMessage('I do not like this value!');
   ExprPart.Return(ExprPart.Arg(1));
End;

procedure ErrRaiseMsgTest();
begin
   
   uc.DefineFunction('ErrRaiseMsgTest(Value)', ErrRaiseMsgTestCB);
   WriteLn(uc.EvalStr('ErrRaiseMsgTest(111)')); // Returns 111;
   WriteLn(uc.EvalStr('ErrRaiseMsgTest(123)')); // Returns 'I do not like this value!'; // Our callback arbitrarily raises an error for 123
End;

          

void _stdcall ErrRaiseMsgTestCB(uCalcPtr ExprPartPtr) {
   auto ExprPart = uCalc::Callback(ExprPartPtr);
   if (ExprPart.Arg(1) == 123) ExprPart.ErrorRaiseMessage("I do not like this value!");
   ExprPart.Return(ExprPart.Arg(1));
}

void ErrRaiseMsgTest() {
   uc.DefineFunction("ErrRaiseMsgTest(Value)", ErrRaiseMsgTestCB);
   cout << uc.EvalStr("ErrRaiseMsgTest(111)") << endl; // Returns 111;
   cout << uc.EvalStr("ErrRaiseMsgTest(123)") << endl; // Returns "I do not like this value!"; // Our callback arbitrarily raises an error for 123
}

          

static void ErrRaiseMsgTestCB(uCalcPtr ExprPartPtr) {
   auto ExprPart = uCalc::Callback(ExprPartPtr);
   if (ExprPart.Arg(1) == 123) ExprPart.ErrorRaiseMessage("I do not like this value!");
   ExprPart.Return(ExprPart.Arg(1));
}

static void ErrRaiseMsgTest() {
   uc.DefineFunction("ErrRaiseMsgTest(Value)", ucPinAddr(ErrRaiseMsgTestCB));
   Console::WriteLine(uc.EvalStr("ErrRaiseMsgTest(111)")); // Returns 111;
   Console::WriteLine(uc.EvalStr("ErrRaiseMsgTest(123)")); // Returns "I do not like this value!"; // Our callback arbitrarily raises an error for 123
}

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

Private Function ErrorRaiseMessage__(ByVal ExprPartHandle As IntPtr,ByVal ErrMessage As String) As  Int32
End Function
            
[DllImport(uCalcDLL, CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl, EntryPoint="ErrorRaiseMessage")]

protected static extern  Int32 ErrorRaiseMessage_(IntPtr ExprPartHandle, string ErrMessage);
            
{DLLImport}function ErrorRaiseMessage__(ExprPartHandle: System.Pointer;ErrMessage: AnsiString):  Int32; cdecl; external uCalcDLL name 'ErrorRaiseMessage';

            
typedef  int32_t (* __ErrorRaiseMessage)(void *ExprPartHandle, CONSTCHAR ErrMessage ); 

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

static Int32 ErrorRaiseMessage_(void *  ExprPartHandle, MARSHALSTR ErrMessage);
            
Prev | Next