Internal Test: An overflow error is intercepted by a custom error handler.

ID: 411

				
					using uCalcSoftware;

var uc = new uCalc();

static void MyErrorHandler(Handle_uCalc h) {
   var uc = new uCalc(h);
   Console.WriteLine("--- Error Handler Caught ---");
   Console.WriteLine($"  Code: {(int)uc.Error.Code}");
   Console.WriteLine($"  Message: {uc.Error.Message}");
   // Abort is the default response, no need to set it.
}


// Register the custom error handler
uc.Error.AddHandler(MyErrorHandler);

// Configure the engine to raise an error on overflow
uc.Error.TrapOnOverflow = true;

// This evaluation will now be intercepted by our handler
Console.WriteLine("Evaluating expression '1e999'...");
uc.EvalStr("1e999"); // This triggers the callback
Console.WriteLine("Evaluation finished.");
				
			
Evaluating expression '1e999'...
--- Error Handler Caught ---
  Code: 4
  Message: Floating point overflow
Evaluation finished.
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

void ucalc_call MyErrorHandler(Handle_uCalc h) {
   auto uc = uCalc(h);
   cout << "--- Error Handler Caught ---" << endl;
   cout << "  Code: " << (int)uc.Error().Code() << endl;
   cout << "  Message: " << uc.Error().Message() << endl;
   // Abort is the default response, no need to set it.
}

int main() {
   uCalc uc;
   // Register the custom error handler
   uc.Error().AddHandler(MyErrorHandler);

   // Configure the engine to raise an error on overflow
   uc.Error().TrapOnOverflow(true);

   // This evaluation will now be intercepted by our handler
   cout << "Evaluating expression '1e999'..." << endl;
   uc.EvalStr("1e999"); // This triggers the callback
   cout << "Evaluation finished." << endl;
}
				
			
Evaluating expression '1e999'...
--- Error Handler Caught ---
  Code: 4
  Message: Floating point overflow
Evaluation finished.
				
					Imports System
Imports uCalcSoftware
Public Module Program
   
   Public Sub MyErrorHandler(ByVal h As Handle_uCalc)
      Dim uc As New uCalc(h)
      Console.WriteLine("--- Error Handler Caught ---")
      Console.WriteLine($"  Code: {CInt(uc.Error.Code)}")
      Console.WriteLine($"  Message: {uc.Error.Message}")
      '// Abort is the default response, no need to set it.
   End Sub
   
   Public Sub Main()
      Dim uc As New uCalc()
      '// Register the custom error handler
      uc.Error.AddHandler(AddressOf MyErrorHandler)
      
      '// Configure the engine to raise an error on overflow
      uc.Error.TrapOnOverflow = true
      
      '// This evaluation will now be intercepted by our handler
      Console.WriteLine("Evaluating expression '1e999'...")
      uc.EvalStr("1e999") '// This triggers the callback
      Console.WriteLine("Evaluation finished.")
   End Sub
End Module
				
			
Evaluating expression '1e999'...
--- Error Handler Caught ---
  Code: 4
  Message: Floating point overflow
Evaluation finished.