ErrorRaiseMessageMethod
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
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)"))
Console.WriteLine(uc.EvalStr("ErrRaiseMsgTest(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)"));
Console.WriteLine(uc.EvalStr("ErrRaiseMsgTest(123)"));
}
procedure ErrRaiseMsgTestCB(ExprPartPtr: System.Pointer);
begin
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)'));
WriteLn(uc.EvalStr('ErrRaiseMsgTest(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;
cout << uc.EvalStr("ErrRaiseMsgTest(123)") << endl;
}
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)"));
Console::WriteLine(uc.EvalStr("ErrRaiseMsgTest(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);