uCalc API Version: 2.1.3-preview.2 Released: 6/17/2026

Warning

uCalc API Preview Release Notice:The documentation describes the intended behavior of the API. The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.

Response = [ErrorHandlerResponse]

Property

Product: 

Fast Math Parser

Class: 

ErrorInfo

Determines the engine's behavior after an error handler callback finishes executing.

Remarks

The Response property is the primary control mechanism used inside an AddErrorHandler callback to dictate the flow of execution after an error has been intercepted. It determines whether the engine should abort the operation, attempt to recover and continue, or delegate the error to another handler in the chain.

This method can only be called from within an error handler's callback function.


⚙️ Handler Responses

You must provide a value from the ErrorHandlerResponse enum:

  • ErrorHandlerResponse::Abort (Default)This is the standard behavior. It immediately halts the parsing or evaluation process. The original function call (e.g., EvalStr) will fail and return an error message. Use this when the error is unrecoverable.

  • ErrorHandlerResponse::ResumeThis powerful option instructs the uCalc engine to continue execution from where it left off, as if the error never occurred. This is ideal for creating robust, fault-tolerant applications that can recover from invalid input.

    ⚠️ Important: Before resuming, your handler must resolve the condition that caused the error. For example, if the error was Undefined_Identifier, you might define the variable. Failure to resolve the issue will likely cause an infinite loop as the engine repeatedly encounters the same error.

  • ErrorHandlerResponse::ReRaiseThis passes the current error to the next handler in the stack. It allows for creating layered or tiered error-handling strategies. For instance, an initial handler might simply log all errors and then ReRaise them, allowing a more specific, subsequent handler to decide whether to Abort or Resume.


Comparative Analysis

  • vs. Traditional try-catchStandard exception handling in languages like C# and C++ is primarily about unwinding the stack and aborting a block of code. try-catch provides a way to fail gracefully. uCalc's model, particularly with Resume, offers a fundamentally different paradigm: error recovery. It allows an operation to be repaired and continued, which is essential for interactive applications, live editors, or long-running calculations where simply aborting is not desirable.

  • vs. LISP Condition SystemThe combination of intercepting an error, choosing a recovery strategy (Resume), and delegating responsibility (ReRaise) is conceptually similar to the highly-regarded Common Lisp Condition System. This system separates the act of signaling an error from the logic that handles it, providing a level of flexibility rarely seen outside of Lisp-like languages. This makes uCalc's error handling exceptionally powerful for complex parsing and evaluation tasks.

Examples

Practical: Creates a robust error handler that automatically defines variables on-the-fly when an 'Undefined Identifier' error occurs.
				
					using uCalcSoftware;

var uc = new uCalc();

// This error handler allows you to use variables that were not
// explicitly defined previously by defining unrecognized identifiers
// as variables instead of returning an error.
static void AutoVariableDef(Handle_uCalc h) {
   var uc = new uCalc(h);
   if (uc.Error.Code == ErrorCode.Undefined_Identifier) {
      uc.DefineVariable(uc.Error.Symbol);
      uc.Error.Response = ErrorHandlerResponse.Resume;
   }
}


uc.Error.AddHandler(AutoVariableDef);
// The handler will automatically define 'AutoTest' on first use.
Console.WriteLine(uc.Eval("AutoTest = 123"));
Console.WriteLine(uc.Eval("AutoTest * 1000"));
				
			
123
123000
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

// This error handler allows you to use variables that were not
// explicitly defined previously by defining unrecognized identifiers
// as variables instead of returning an error.
void ucalc_call AutoVariableDef(Handle_uCalc h) {
   auto uc = uCalc(h);
   if (uc.Error().Code() == ErrorCode::Undefined_Identifier) {
      uc.DefineVariable(uc.Error().Symbol());
      uc.Error().Response(ErrorHandlerResponse::Resume);
   }
}

int main() {
   uCalc uc;
   uc.Error().AddHandler(AutoVariableDef);
   // The handler will automatically define 'AutoTest' on first use.
   cout << uc.Eval("AutoTest = 123") << endl;
   cout << uc.Eval("AutoTest * 1000") << endl;
}
				
			
123
123000
				
					Imports System
Imports uCalcSoftware
Public Module Program
   
   '// This error handler allows you to use variables that were not
   '// explicitly defined previously by defining unrecognized identifiers
   '// as variables instead of returning an error.
   Public Sub AutoVariableDef(ByVal h As Handle_uCalc)
      Dim uc As New uCalc(h)
      If uc.Error.Code = ErrorCode.Undefined_Identifier Then
         uc.DefineVariable(uc.Error.Symbol)
         uc.Error.Response = ErrorHandlerResponse.Resume
      End If
   End Sub
   
   Public Sub Main()
      Dim uc As New uCalc()
      uc.Error.AddHandler(AddressOf AutoVariableDef)
      '// The handler will automatically define 'AutoTest' on first use.
      Console.WriteLine(uc.Eval("AutoTest = 123"))
      Console.WriteLine(uc.Eval("AutoTest * 1000"))
   End Sub
End Module
				
			
123
123000
Error handler to auto-define variables
				
					using uCalcSoftware;

var uc = new uCalc();

// This error handler allows you to use variables that were not
// explicitly defined previously, by defining the unrecognized identifiers
// as variables instead of returning an error
static void AutoVariableDef(Handle_uCalc h) {
   var uc = new uCalc(h);
   if (uc.Error.Code == ErrorCode.Undefined_Identifier) {
      uc.DefineVariable(uc.Error.Symbol);
      uc.Error.Response = ErrorHandlerResponse.Resume;
   }
}


uc.Error.AddHandler(AutoVariableDef);
Console.WriteLine(uc.Eval("AutoTest = 123"));
Console.WriteLine(uc.Eval("AutoTest * 1000"));
				
			
123
123000
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

// This error handler allows you to use variables that were not
// explicitly defined previously, by defining the unrecognized identifiers
// as variables instead of returning an error
void ucalc_call AutoVariableDef(Handle_uCalc h) {
   auto uc = uCalc(h);
   if (uc.Error().Code() == ErrorCode::Undefined_Identifier) {
      uc.DefineVariable(uc.Error().Symbol());
      uc.Error().Response(ErrorHandlerResponse::Resume);
   }
}

int main() {
   uCalc uc;
   uc.Error().AddHandler(AutoVariableDef);
   cout << uc.Eval("AutoTest = 123") << endl;
   cout << uc.Eval("AutoTest * 1000") << endl;
}
				
			
123
123000
				
					Imports System
Imports uCalcSoftware
Public Module Program
   
   '// This error handler allows you to use variables that were not
   '// explicitly defined previously, by defining the unrecognized identifiers
   '// as variables instead of returning an error
   Public Sub AutoVariableDef(ByVal h As Handle_uCalc)
      Dim uc As New uCalc(h)
      If uc.Error.Code = ErrorCode.Undefined_Identifier Then
         uc.DefineVariable(uc.Error.Symbol)
         uc.Error.Response = ErrorHandlerResponse.Resume
      End If
   End Sub
   
   Public Sub Main()
      Dim uc As New uCalc()
      uc.Error.AddHandler(AddressOf AutoVariableDef)
      Console.WriteLine(uc.Eval("AutoTest = 123"))
      Console.WriteLine(uc.Eval("AutoTest * 1000"))
   End Sub
End Module
				
			
123
123000