using uCalcSoftware; var uc = new uCalc(); static void AutoDefineHandler(Handle_uCalc h) { var uc = new uCalc(h); // Check if the error is specifically an undefined identifier if (uc.Error.Code == ErrorCode.Undefined_Identifier) { // If so, define the missing variable and instruct uCalc to resume Console.WriteLine($"Auto-defining variable: '{uc.Error.Symbol}'"); uc.DefineVariable(uc.Error.Symbol); uc.Error.Response = ErrorHandlerResponse.Resume; } } uc.Error.AddHandler(AutoDefineHandler); // 'x' doesn't exist, but the handler will intercept the error and create it. var Result = uc.EvalStr("x = 10; x * 5"); Console.WriteLine($"Result: {Result}");