using uCalcSoftware;

var uc = new uCalc();

static void RecoveryHandler(Handle_uCalc h) {
   var uc = new uCalc(h);
   Console.WriteLine($"Handler: Caught '{uc.Error.Message}'");
   // Attempt to recover by resuming execution.
   uc.Error.Response = ErrorHandlerResponse.Resume;
   Console.WriteLine("Handler: Resuming execution...");
}
static void RiskyOperation(uCalc.Callback cb) {
   var input = cb.ArgStr(1);
   if (input == "bad") {
      cb.Error.Raise("A recoverable error occurred.");
      // After the error handler resumes, this return value will be used.

   } else {
      cb.ReturnStr("Normal_OK");
   }
}

uc.Error.AddHandler(RecoveryHandler);
uc.DefineFunction("DoWork(s As String) As String", RiskyOperation);

Console.WriteLine("Result: " + uc.EvalStr("DoWork('good')"));
Console.WriteLine("---");
Console.WriteLine("Result: " + uc.EvalStr("DoWork('bad')"));