A function that unconditionally raises a custom error.

ID: 482

				
					using uCalcSoftware;

var uc = new uCalc();

static void MyHandler(Handle_uCalc h) {
   var uc = new uCalc(h);
   // This handler just logs the error and aborts
   Console.WriteLine($"Error Handler Caught: {uc.Error.Message}");
}
static void MyFunc(uCalc.Callback cb) {
   // This function always fails with a custom message
   cb.Error.Raise("Validation failed for input.");
}

uc.Error.AddHandler(MyHandler);
uc.DefineFunction("Validate()", MyFunc);
uc.EvalStr("Validate()"); // This call will trigger the error
				
			
Error Handler Caught: Validation failed for input.
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

void ucalc_call MyHandler(Handle_uCalc h) {
   auto uc = uCalc(h);
   // This handler just logs the error and aborts
   cout << "Error Handler Caught: " << uc.Error().Message() << endl;
}
void ucalc_call MyFunc(uCalcBase::Callback cb) {
   // This function always fails with a custom message
   cb.Error().Raise("Validation failed for input.");
}
int main() {
   uCalc uc;
   uc.Error().AddHandler(MyHandler);
   uc.DefineFunction("Validate()", MyFunc);
   uc.EvalStr("Validate()"); // This call will trigger the error
}
				
			
Error Handler Caught: Validation failed for input.
				
					Imports System
Imports uCalcSoftware
Public Module Program
   
   Public Sub MyHandler(ByVal h As Handle_uCalc)
      Dim uc As New uCalc(h)
      '// This handler just logs the error and aborts
      Console.WriteLine($"Error Handler Caught: {uc.Error.Message}")
   End Sub
   Public Sub MyFunc(ByVal cb As uCalc.Callback)
      '// This function always fails with a custom message
      cb.Error.Raise("Validation failed for input.")
   End Sub
   Public Sub Main()
      Dim uc As New uCalc()
      uc.Error.AddHandler(AddressOf MyHandler)
      uc.DefineFunction("Validate()", AddressOf MyFunc)
      uc.EvalStr("Validate()") '// This call will trigger the error
   End Sub
End Module
				
			
Error Handler Caught: Validation failed for input.