uCalc API Version: 2.1.3-preview.2 Released: 6/16/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.

Expression = [string]

Property

Product: 

Fast Math Parser

Class: 

ErrorInfo

Returns the full expression string that was being processed when a parsing error occurred.

Remarks

This property is a key diagnostic tool used within an error handler callback to retrieve the source expression that triggered a parsing-stage error.

When uCalc processes an expression with a function like EvalStr(), errors can occur at two distinct stages:

  1. Parsing Stage: This is when uCalc analyzes the structure and syntax of the input string. Errors include syntax mistakes, undefined identifiers, or mismatched brackets. During this stage, ErrorExpression() returns the complete, original expression string.

  2. Evaluation Stage: This occurs after a successful parse, when uCalc executes the parsed tree. Errors include division by zero, invalid function arguments, or floating-point overflows. During this stage, the original expression string is no longer in context, so ErrorExpression() returns an empty string.

This distinction is crucial for building robust error handlers. By checking if ErrorExpression() is empty, a handler can determine whether the failure was syntactic or computational.

Usage in Error Handlers

This method is almost exclusively called from within a callback registered with uCalc.AddErrorHandler(). It works in conjunction with other diagnostic functions to provide a complete picture of the error:

# Comparative Analysis

In standard programming languages like C# or C++, a try-catch block provides an exception object with properties like Message and StackTrace. However, it typically does not give you the original line of source code or expression string that failed. ErrorExpression() provides this high-level context directly, allowing for more intelligent error reporting and even programmatic correction, which is a significant advantage of uCalc's error handling model.

Examples

An internal test to confirm that ErrorExpression returns an empty string for an error triggered manually by a user function during evaluation.
				
					using uCalcSoftware;

var uc = new uCalc();

static void MyFunc(uCalc.Callback cb) {
   // This error occurs during evaluation, not parsing.
   cb.Error.Raise("Manual evaluation failure!");
}

static void MyHandler(Handle_uCalc h) {
   var uc = new uCalc(h);
   Console.WriteLine($"Handler triggered for error: {uc.Error.Message}");
   Console.WriteLine($"ErrorExpression() returned: '{uc.Error.Expression}'");
   Console.WriteLine($"Is expression empty? {uc.Error.Expression == ""}");
}


uc.DefineFunction("MyFunc()", MyFunc);
uc.Error.AddHandler(MyHandler);

// The expression 'MyFunc()' itself is valid syntactically.
Console.WriteLine(uc.EvalStr("MyFunc()"));
				
			
Handler triggered for error: Manual evaluation failure!
ErrorExpression() returned: ''
Is expression empty? True
Manual evaluation failure!
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

#define tf(IsTrue) ((IsTrue) ? "True" : "False")

void ucalc_call MyFunc(uCalcBase::Callback cb) {
   // This error occurs during evaluation, not parsing.
   cb.Error().Raise("Manual evaluation failure!");
}

void ucalc_call MyHandler(Handle_uCalc h) {
   auto uc = uCalc(h);
   cout << "Handler triggered for error: " << uc.Error().Message() << endl;
   cout << "ErrorExpression() returned: '" << uc.Error().Expression() << "'" << endl;
   cout << "Is expression empty? " << tf(uc.Error().Expression() == "") << endl;
}

int main() {
   uCalc uc;
   uc.DefineFunction("MyFunc()", MyFunc);
   uc.Error().AddHandler(MyHandler);

   // The expression 'MyFunc()' itself is valid syntactically.
   cout << uc.EvalStr("MyFunc()") << endl;
}
				
			
Handler triggered for error: Manual evaluation failure!
ErrorExpression() returned: ''
Is expression empty? True
Manual evaluation failure!
				
					Imports System
Imports uCalcSoftware
Public Module Program
   
   Public Sub MyFunc(ByVal cb As uCalc.Callback)
      '// This error occurs during evaluation, not parsing.
      cb.Error.Raise("Manual evaluation failure!")
   End Sub
   
   Public Sub MyHandler(ByVal h As Handle_uCalc)
      Dim uc As New uCalc(h)
      Console.WriteLine($"Handler triggered for error: {uc.Error.Message}")
      Console.WriteLine($"ErrorExpression() returned: '{uc.Error.Expression}'")
      Console.WriteLine($"Is expression empty? {uc.Error.Expression = ""}")
   End Sub
   
   Public Sub Main()
      Dim uc As New uCalc()
      uc.DefineFunction("MyFunc()", AddressOf MyFunc)
      uc.Error.AddHandler(AddressOf MyHandler)
      
      '// The expression 'MyFunc()' itself is valid syntactically.
      Console.WriteLine(uc.EvalStr("MyFunc()"))
   End Sub
End Module
				
			
Handler triggered for error: Manual evaluation failure!
ErrorExpression() returned: ''
Is expression empty? True
Manual evaluation failure!
Adding an error handler callback
				
					using uCalcSoftware;

var uc = new uCalc();

static void MyErrorHandler(Handle_uCalc h) {
   var uc = new uCalc(h);
   Console.WriteLine("An error has occurred!");
   Console.WriteLine($"Error #: {(int)uc.Error.Code}");
   Console.WriteLine($"Error Message: {uc.Error.Message}");
   Console.WriteLine($"Error Symbol: {uc.Error.Symbol}");
   Console.WriteLine($"Error Location: {uc.Error.Location}");
   Console.WriteLine($"Error Expression: {uc.Error.Expression}");
}


uc.Error.AddHandler(MyErrorHandler);
Console.WriteLine(uc.EvalStr("123+"));
Console.WriteLine("");

uc.Error.TrapOnDivideByZero = true;
Console.WriteLine(uc.EvalStr("5/0"));
				
			
An error has occurred!
Error #: 257
Error Message: Syntax error
Error Symbol: +
Error Location: 3
Error Expression: 123+
Syntax error

An error has occurred!
Error #: 8
Error Message: Division by 0
Error Symbol: 
Error Location: 0
Error Expression: 
Division by 0
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

void ucalc_call MyErrorHandler(Handle_uCalc h) {
   auto uc = uCalc(h);
   cout << "An error has occurred!" << endl;
   cout << "Error #: " << (int)uc.Error().Code() << endl;
   cout << "Error Message: " << uc.Error().Message() << endl;
   cout << "Error Symbol: " << uc.Error().Symbol() << endl;
   cout << "Error Location: " << uc.Error().Location() << endl;
   cout << "Error Expression: " << uc.Error().Expression() << endl;
}

int main() {
   uCalc uc;
   uc.Error().AddHandler(MyErrorHandler);
   cout << uc.EvalStr("123+") << endl;
   cout << "" << endl;

   uc.Error().TrapOnDivideByZero(true);
   cout << uc.EvalStr("5/0") << endl;
}
				
			
An error has occurred!
Error #: 257
Error Message: Syntax error
Error Symbol: +
Error Location: 3
Error Expression: 123+
Syntax error

An error has occurred!
Error #: 8
Error Message: Division by 0
Error Symbol: 
Error Location: 0
Error Expression: 
Division by 0
				
					Imports System
Imports uCalcSoftware
Public Module Program
   
   Public Sub MyErrorHandler(ByVal h As Handle_uCalc)
      Dim uc As New uCalc(h)
      Console.WriteLine("An error has occurred!")
      Console.WriteLine($"Error #: {CInt(uc.Error.Code)}")
      Console.WriteLine($"Error Message: {uc.Error.Message}")
      Console.WriteLine($"Error Symbol: {uc.Error.Symbol}")
      Console.WriteLine($"Error Location: {uc.Error.Location}")
      Console.WriteLine($"Error Expression: {uc.Error.Expression}")
   End Sub
   
   Public Sub Main()
      Dim uc As New uCalc()
      uc.Error.AddHandler(AddressOf MyErrorHandler)
      Console.WriteLine(uc.EvalStr("123+"))
      Console.WriteLine("")
      
      uc.Error.TrapOnDivideByZero = true
      Console.WriteLine(uc.EvalStr("5/0"))
   End Sub
End Module
				
			
An error has occurred!
Error #: 257
Error Message: Syntax error
Error Symbol: +
Error Location: 3
Error Expression: 123+
Syntax error

An error has occurred!
Error #: 8
Error Message: Division by 0
Error Symbol: 
Error Location: 0
Error Expression: 
Division by 0