#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

void ucalc_call MyErrorHandler(Handle_uCalc h) {
   auto uc = uCalc(h);
   // Check if the specific 'FloatInvalid' error was raised
   if (uc.Error().Code() == ErrorCode::FloatInvalid) {
      cout << "Error: The calculation resulted in an invalid number (e.g., square root of a negative)." << endl;
      // Stop further processing
      uc.Error().Response(ErrorHandlerResponse::Abort);
   }
}

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

   // Tell uCalc to raise an error instead of returning 'nan'
   uc.Error().TrapOnInvalid(true);

   // This will now trigger our custom error handler's message
   uc.EvalStr("sqrt(-4)");
}