#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;
}