uCalc API Version: 5.7.0-preview.1 Released: 7/30/2026
Warning
uCalc API Preview Release Notice:This preview documentation describes the intended behavior of the API. It is not fully accurate or complete.The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.Use of the preview version in your production code is not recommended.
Product:
Class:
ErrorInfo object with details like error location, message, etc.
ID: 1
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 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"));
#include
#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 #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; }
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 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
ID: 327
using uCalcSoftware;
var uc = new uCalc();
// Trigger an error and check the code
uc.EvalStr("1+");
Console.WriteLine($"1. Error code after failure: {(int)uc.Error.Code}");
// A successful evaluation should clear the error code
uc.EvalStr("1+1");
Console.WriteLine($"2. Error code after success: {(int)uc.Error.Code}");
// Trigger a different type of error
uc.Error.TrapOnDivideByZero = true;
uc.EvalStr("1/0");
Console.WriteLine($"3. Error code after new failure: {(int)uc.Error.Code}");
// A successful definition should also clear the error code
uc.DefineVariable("x=5");
Console.WriteLine($"4. Error code after successful definition: {(int)uc.Error.Code}");
1. Error code after failure: 257
2. Error code after success: 0
3. Error code after new failure: 8
4. Error code after successful definition: 0 using uCalcSoftware; var uc = new uCalc(); // Trigger an error and check the code uc.EvalStr("1+"); Console.WriteLine($"1. Error code after failure: {(int)uc.Error.Code}"); // A successful evaluation should clear the error code uc.EvalStr("1+1"); Console.WriteLine($"2. Error code after success: {(int)uc.Error.Code}"); // Trigger a different type of error uc.Error.TrapOnDivideByZero = true; uc.EvalStr("1/0"); Console.WriteLine($"3. Error code after new failure: {(int)uc.Error.Code}"); // A successful definition should also clear the error code uc.DefineVariable("x=5"); Console.WriteLine($"4. Error code after successful definition: {(int)uc.Error.Code}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// Trigger an error and check the code
uc.EvalStr("1+");
cout << "1. Error code after failure: " << (int)uc.Error().Code() << endl;
// A successful evaluation should clear the error code
uc.EvalStr("1+1");
cout << "2. Error code after success: " << (int)uc.Error().Code() << endl;
// Trigger a different type of error
uc.Error().TrapOnDivideByZero(true);
uc.EvalStr("1/0");
cout << "3. Error code after new failure: " << (int)uc.Error().Code() << endl;
// A successful definition should also clear the error code
uc.DefineVariable("x=5");
cout << "4. Error code after successful definition: " << (int)uc.Error().Code() << endl;
}
1. Error code after failure: 257
2. Error code after success: 0
3. Error code after new failure: 8
4. Error code after successful definition: 0 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Trigger an error and check the code uc.EvalStr("1+"); cout << "1. Error code after failure: " << (int)uc.Error().Code() << endl; // A successful evaluation should clear the error code uc.EvalStr("1+1"); cout << "2. Error code after success: " << (int)uc.Error().Code() << endl; // Trigger a different type of error uc.Error().TrapOnDivideByZero(true); uc.EvalStr("1/0"); cout << "3. Error code after new failure: " << (int)uc.Error().Code() << endl; // A successful definition should also clear the error code uc.DefineVariable("x=5"); cout << "4. Error code after successful definition: " << (int)uc.Error().Code() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Trigger an error and check the code
uc.EvalStr("1+")
Console.WriteLine($"1. Error code after failure: {uc.Error.Code.ToString("D")}")
'// A successful evaluation should clear the error code
uc.EvalStr("1+1")
Console.WriteLine($"2. Error code after success: {uc.Error.Code.ToString("D")}")
'// Trigger a different type of error
uc.Error.TrapOnDivideByZero = true
uc.EvalStr("1/0")
Console.WriteLine($"3. Error code after new failure: {uc.Error.Code.ToString("D")}")
'// A successful definition should also clear the error code
uc.DefineVariable("x=5")
Console.WriteLine($"4. Error code after successful definition: {uc.Error.Code.ToString("D")}")
End Sub
End Module
1. Error code after failure: 257
2. Error code after success: 0
3. Error code after new failure: 8
4. Error code after successful definition: 0 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Trigger an error and check the code uc.EvalStr("1+") Console.WriteLine($"1. Error code after failure: {uc.Error.Code.ToString("D")}") '// A successful evaluation should clear the error code uc.EvalStr("1+1") Console.WriteLine($"2. Error code after success: {uc.Error.Code.ToString("D")}") '// Trigger a different type of error uc.Error.TrapOnDivideByZero = true uc.EvalStr("1/0") Console.WriteLine($"3. Error code after new failure: {uc.Error.Code.ToString("D")}") '// A successful definition should also clear the error code uc.DefineVariable("x=5") Console.WriteLine($"4. Error code after successful definition: {uc.Error.Code.ToString("D")}") End Sub End Module
ID: 326
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}");
Auto-defining variable: 'x'
Result: 50 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}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
void ucalc_call AutoDefineHandler(Handle_uCalc h) {
auto uc = 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
cout << "Auto-defining variable: '" << uc.Error().Symbol() << "'" << endl;
uc.DefineVariable(uc.Error().Symbol());
uc.Error().Response(ErrorHandlerResponse::Resume);
}
}
int main() {
uCalc uc;
uc.Error().AddHandler(AutoDefineHandler);
// 'x' doesn't exist, but the handler will intercept the error and create it.
auto Result = uc.EvalStr("x = 10; x * 5");
cout << "Result: " << Result << endl;
}
Auto-defining variable: 'x'
Result: 50 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; void ucalc_call AutoDefineHandler(Handle_uCalc h) { auto uc = 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 cout << "Auto-defining variable: '" << uc.Error().Symbol() << "'" << endl; uc.DefineVariable(uc.Error().Symbol()); uc.Error().Response(ErrorHandlerResponse::Resume); } } int main() { uCalc uc; uc.Error().AddHandler(AutoDefineHandler); // 'x' doesn't exist, but the handler will intercept the error and create it. auto Result = uc.EvalStr("x = 10; x * 5"); cout << "Result: " << Result << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub AutoDefineHandler(ByVal h As Handle_uCalc)
Dim uc As New uCalc(h)
'// Check if the error is specifically an undefined identifier
If uc.Error.Code = ErrorCode.Undefined_Identifier Then
'// 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
End If
End Sub
Public Sub Main()
Dim uc As New uCalc()
uc.Error.AddHandler(AddressOf AutoDefineHandler)
'// 'x' doesn't exist, but the handler will intercept the error and create it.
Dim Result = uc.EvalStr("x = 10; x * 5")
Console.WriteLine($"Result: {Result}")
End Sub
End Module
Auto-defining variable: 'x'
Result: 50 Imports System Imports uCalcSoftware Public Module Program Public Sub AutoDefineHandler(ByVal h As Handle_uCalc) Dim uc As New uCalc(h) '// Check if the error is specifically an undefined identifier If uc.Error.Code = ErrorCode.Undefined_Identifier Then '// 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 End If End Sub Public Sub Main() Dim uc As New uCalc() uc.Error.AddHandler(AddressOf AutoDefineHandler) '// 'x' doesn't exist, but the handler will intercept the error and create it. Dim Result = uc.EvalStr("x = 10; x * 5") Console.WriteLine($"Result: {Result}") End Sub End Module
ID: 325
using uCalcSoftware;
var uc = new uCalc();
static void MyHandler(Handle_uCalc h) {
var uc = new uCalc(h);
// Retrieve the error code as an integer for display
int code = (int)uc.Error.Code;
Console.WriteLine($"Caught Error Code: {code}");
// Compare the error code against the ErrorCode enum for logic
if (uc.Error.Code == ErrorCode.Syntax_Error) {
Console.WriteLine("This was a syntax error.");
}
}
// Register the error handler
uc.Error.AddHandler(MyHandler);
// Intentionally cause a syntax error, which will trigger the handler
Console.WriteLine(uc.EvalStr("5 *"));
Caught Error Code: 257
This was a syntax error.
Syntax error using uCalcSoftware; var uc = new uCalc(); static void MyHandler(Handle_uCalc h) { var uc = new uCalc(h); // Retrieve the error code as an integer for display int code = (int)uc.Error.Code; Console.WriteLine($"Caught Error Code: {code}"); // Compare the error code against the ErrorCode enum for logic if (uc.Error.Code == ErrorCode.Syntax_Error) { Console.WriteLine("This was a syntax error."); } } // Register the error handler uc.Error.AddHandler(MyHandler); // Intentionally cause a syntax error, which will trigger the handler Console.WriteLine(uc.EvalStr("5 *"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
void ucalc_call MyHandler(Handle_uCalc h) {
auto uc = uCalc(h);
// Retrieve the error code as an integer for display
int code = (int)uc.Error().Code();
cout << "Caught Error Code: " << code << endl;
// Compare the error code against the ErrorCode enum for logic
if (uc.Error().Code() == ErrorCode::Syntax_Error) {
cout << "This was a syntax error." << endl;
}
}
int main() {
uCalc uc;
// Register the error handler
uc.Error().AddHandler(MyHandler);
// Intentionally cause a syntax error, which will trigger the handler
cout << uc.EvalStr("5 *") << endl;
}
Caught Error Code: 257
This was a syntax error.
Syntax error #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; void ucalc_call MyHandler(Handle_uCalc h) { auto uc = uCalc(h); // Retrieve the error code as an integer for display int code = (int)uc.Error().Code(); cout << "Caught Error Code: " << code << endl; // Compare the error code against the ErrorCode enum for logic if (uc.Error().Code() == ErrorCode::Syntax_Error) { cout << "This was a syntax error." << endl; } } int main() { uCalc uc; // Register the error handler uc.Error().AddHandler(MyHandler); // Intentionally cause a syntax error, which will trigger the handler cout << uc.EvalStr("5 *") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub MyHandler(ByVal h As Handle_uCalc)
Dim uc As New uCalc(h)
'// Retrieve the error code as an integer for display
Dim code As Integer = uc.Error.Code
Console.WriteLine($"Caught Error Code: {code}")
'// Compare the error code against the ErrorCode enum for logic
If uc.Error.Code = ErrorCode.Syntax_Error Then
Console.WriteLine("This was a syntax error.")
End If
End Sub
Public Sub Main()
Dim uc As New uCalc()
'// Register the error handler
uc.Error.AddHandler(AddressOf MyHandler)
'// Intentionally cause a syntax error, which will trigger the handler
Console.WriteLine(uc.EvalStr("5 *"))
End Sub
End Module
Caught Error Code: 257
This was a syntax error.
Syntax error Imports System Imports uCalcSoftware Public Module Program Public Sub MyHandler(ByVal h As Handle_uCalc) Dim uc As New uCalc(h) '// Retrieve the error code as an integer for display Dim code As Integer = uc.Error.Code Console.WriteLine($"Caught Error Code: {code}") '// Compare the error code against the ErrorCode enum for logic If uc.Error.Code = ErrorCode.Syntax_Error Then Console.WriteLine("This was a syntax error.") End If End Sub Public Sub Main() Dim uc As New uCalc() '// Register the error handler uc.Error.AddHandler(AddressOf MyHandler) '// Intentionally cause a syntax error, which will trigger the handler Console.WriteLine(uc.EvalStr("5 *")) End Sub End Module
ID: 318
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! 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()"));
#include
#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! #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; }
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! 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
ID: 321
using uCalcSoftware;
var uc = new uCalc();
static void MyErrorHandler(Handle_uCalc h) {
var uc = new uCalc(h);
Console.WriteLine("--- Error Captured ---");
Console.WriteLine($"Message: {uc.Error.Message}");
Console.WriteLine($"Symbol: '{uc.Error.Symbol}'");
Console.WriteLine($"Location: {uc.Error.Location}");
Console.WriteLine($"Expression: '{uc.Error.Expression}'");
}
uc.Error.AddHandler(MyErrorHandler);
Console.WriteLine("Demonstrating a PARSING error:");
uc.EvalStr("123//456");
Console.WriteLine("");
Console.WriteLine("Demonstrating an EVALUATION error:");
uc.Error.TrapOnDivideByZero = true;
uc.EvalStr("5/0");
Demonstrating a PARSING error:
--- Error Captured ---
Message: Syntax error
Symbol: '/'
Location: 3
Expression: '123//456'
Demonstrating an EVALUATION error:
--- Error Captured ---
Message: Division by 0
Symbol: ''
Location: 0
Expression: '' using uCalcSoftware; var uc = new uCalc(); static void MyErrorHandler(Handle_uCalc h) { var uc = new uCalc(h); Console.WriteLine("--- Error Captured ---"); Console.WriteLine($"Message: {uc.Error.Message}"); Console.WriteLine($"Symbol: '{uc.Error.Symbol}'"); Console.WriteLine($"Location: {uc.Error.Location}"); Console.WriteLine($"Expression: '{uc.Error.Expression}'"); } uc.Error.AddHandler(MyErrorHandler); Console.WriteLine("Demonstrating a PARSING error:"); uc.EvalStr("123//456"); Console.WriteLine(""); Console.WriteLine("Demonstrating an EVALUATION error:"); uc.Error.TrapOnDivideByZero = true; uc.EvalStr("5/0");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
void ucalc_call MyErrorHandler(Handle_uCalc h) {
auto uc = uCalc(h);
cout << "--- Error Captured ---" << endl;
cout << "Message: " << uc.Error().Message() << endl;
cout << "Symbol: '" << uc.Error().Symbol() << "'" << endl;
cout << "Location: " << uc.Error().Location() << endl;
cout << "Expression: '" << uc.Error().Expression() << "'" << endl;
}
int main() {
uCalc uc;
uc.Error().AddHandler(MyErrorHandler);
cout << "Demonstrating a PARSING error:" << endl;
uc.EvalStr("123//456");
cout << "" << endl;
cout << "Demonstrating an EVALUATION error:" << endl;
uc.Error().TrapOnDivideByZero(true);
uc.EvalStr("5/0");
}
Demonstrating a PARSING error:
--- Error Captured ---
Message: Syntax error
Symbol: '/'
Location: 3
Expression: '123//456'
Demonstrating an EVALUATION error:
--- Error Captured ---
Message: Division by 0
Symbol: ''
Location: 0
Expression: '' #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; void ucalc_call MyErrorHandler(Handle_uCalc h) { auto uc = uCalc(h); cout << "--- Error Captured ---" << endl; cout << "Message: " << uc.Error().Message() << endl; cout << "Symbol: '" << uc.Error().Symbol() << "'" << endl; cout << "Location: " << uc.Error().Location() << endl; cout << "Expression: '" << uc.Error().Expression() << "'" << endl; } int main() { uCalc uc; uc.Error().AddHandler(MyErrorHandler); cout << "Demonstrating a PARSING error:" << endl; uc.EvalStr("123//456"); cout << "" << endl; cout << "Demonstrating an EVALUATION error:" << endl; uc.Error().TrapOnDivideByZero(true); uc.EvalStr("5/0"); }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub MyErrorHandler(ByVal h As Handle_uCalc)
Dim uc As New uCalc(h)
Console.WriteLine("--- Error Captured ---")
Console.WriteLine($"Message: {uc.Error.Message}")
Console.WriteLine($"Symbol: '{uc.Error.Symbol}'")
Console.WriteLine($"Location: {uc.Error.Location}")
Console.WriteLine($"Expression: '{uc.Error.Expression}'")
End Sub
Public Sub Main()
Dim uc As New uCalc()
uc.Error.AddHandler(AddressOf MyErrorHandler)
Console.WriteLine("Demonstrating a PARSING error:")
uc.EvalStr("123//456")
Console.WriteLine("")
Console.WriteLine("Demonstrating an EVALUATION error:")
uc.Error.TrapOnDivideByZero = true
uc.EvalStr("5/0")
End Sub
End Module
Demonstrating a PARSING error:
--- Error Captured ---
Message: Syntax error
Symbol: '/'
Location: 3
Expression: '123//456'
Demonstrating an EVALUATION error:
--- Error Captured ---
Message: Division by 0
Symbol: ''
Location: 0
Expression: '' Imports System Imports uCalcSoftware Public Module Program Public Sub MyErrorHandler(ByVal h As Handle_uCalc) Dim uc As New uCalc(h) Console.WriteLine("--- Error Captured ---") Console.WriteLine($"Message: {uc.Error.Message}") Console.WriteLine($"Symbol: '{uc.Error.Symbol}'") Console.WriteLine($"Location: {uc.Error.Location}") Console.WriteLine($"Expression: '{uc.Error.Expression}'") End Sub Public Sub Main() Dim uc As New uCalc() uc.Error.AddHandler(AddressOf MyErrorHandler) Console.WriteLine("Demonstrating a PARSING error:") uc.EvalStr("123//456") Console.WriteLine("") Console.WriteLine("Demonstrating an EVALUATION error:") uc.Error.TrapOnDivideByZero = true uc.EvalStr("5/0") End Sub End Module
ID: 322
using uCalcSoftware;
var uc = new uCalc();
// Attempt to evaluate an expression with unbalanced parenthesis causing a syntax error.
uc.EvalStr("5 * (10 +");
// Check the error message from the last operation.
Console.WriteLine($"Last error message: {uc.Error.Message}");
Last error message: Bracket delimiter error using uCalcSoftware; var uc = new uCalc(); // Attempt to evaluate an expression with unbalanced parenthesis causing a syntax error. uc.EvalStr("5 * (10 +"); // Check the error message from the last operation. Console.WriteLine($"Last error message: {uc.Error.Message}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// Attempt to evaluate an expression with unbalanced parenthesis causing a syntax error.
uc.EvalStr("5 * (10 +");
// Check the error message from the last operation.
cout << "Last error message: " << uc.Error().Message() << endl;
}
Last error message: Bracket delimiter error #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Attempt to evaluate an expression with unbalanced parenthesis causing a syntax error. uc.EvalStr("5 * (10 +"); // Check the error message from the last operation. cout << "Last error message: " << uc.Error().Message() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Attempt to evaluate an expression with unbalanced parenthesis causing a syntax error.
uc.EvalStr("5 * (10 +")
'// Check the error message from the last operation.
Console.WriteLine($"Last error message: {uc.Error.Message}")
End Sub
End Module
Last error message: Bracket delimiter error Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Attempt to evaluate an expression with unbalanced parenthesis causing a syntax error. uc.EvalStr("5 * (10 +") '// Check the error message from the last operation. Console.WriteLine($"Last error message: {uc.Error.Message}") End Sub End Module
ID: 323
using uCalcSoftware;
var uc = new uCalc();
// Retrieve the built-in message for a specific error code, without triggering an error.
Console.WriteLine($"Generic 'Undefined Identifier' message: {uc.Error.GetMessage(ErrorCode.Undefined_Identifier)}");
// Now, trigger a specific error by using an undefined variable.
uc.EvalStr("MyUndefinedVar + 5");
// Check the message and number for the last error that occurred.
Console.WriteLine($"Last error message: {uc.Error.Message}");
Console.WriteLine($"Last error number: {(int)uc.Error.Code}");
Generic 'Undefined Identifier' message: Undefined identifier
Last error message: Undefined identifier
Last error number: 258 using uCalcSoftware; var uc = new uCalc(); // Retrieve the built-in message for a specific error code, without triggering an error. Console.WriteLine($"Generic 'Undefined Identifier' message: {uc.Error.GetMessage(ErrorCode.Undefined_Identifier)}"); // Now, trigger a specific error by using an undefined variable. uc.EvalStr("MyUndefinedVar + 5"); // Check the message and number for the last error that occurred. Console.WriteLine($"Last error message: {uc.Error.Message}"); Console.WriteLine($"Last error number: {(int)uc.Error.Code}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// Retrieve the built-in message for a specific error code, without triggering an error.
cout << "Generic 'Undefined Identifier' message: " << uc.Error().GetMessage(ErrorCode::Undefined_Identifier) << endl;
// Now, trigger a specific error by using an undefined variable.
uc.EvalStr("MyUndefinedVar + 5");
// Check the message and number for the last error that occurred.
cout << "Last error message: " << uc.Error().Message() << endl;
cout << "Last error number: " << (int)uc.Error().Code() << endl;
}
Generic 'Undefined Identifier' message: Undefined identifier
Last error message: Undefined identifier
Last error number: 258 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Retrieve the built-in message for a specific error code, without triggering an error. cout << "Generic 'Undefined Identifier' message: " << uc.Error().GetMessage(ErrorCode::Undefined_Identifier) << endl; // Now, trigger a specific error by using an undefined variable. uc.EvalStr("MyUndefinedVar + 5"); // Check the message and number for the last error that occurred. cout << "Last error message: " << uc.Error().Message() << endl; cout << "Last error number: " << (int)uc.Error().Code() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Retrieve the built-in message for a specific error code, without triggering an error.
Console.WriteLine($"Generic 'Undefined Identifier' message: {uc.Error.GetMessage(ErrorCode.Undefined_Identifier)}")
'// Now, trigger a specific error by using an undefined variable.
uc.EvalStr("MyUndefinedVar + 5")
'// Check the message and number for the last error that occurred.
Console.WriteLine($"Last error message: {uc.Error.Message}")
Console.WriteLine($"Last error number: {CType(uc.Error.Code, Integer)}")
End Sub
End Module
Generic 'Undefined Identifier' message: Undefined identifier
Last error message: Undefined identifier
Last error number: 258 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Retrieve the built-in message for a specific error code, without triggering an error. Console.WriteLine($"Generic 'Undefined Identifier' message: {uc.Error.GetMessage(ErrorCode.Undefined_Identifier)}") '// Now, trigger a specific error by using an undefined variable. uc.EvalStr("MyUndefinedVar + 5") '// Check the message and number for the last error that occurred. Console.WriteLine($"Last error message: {uc.Error.Message}") Console.WriteLine($"Last error number: {CType(uc.Error.Code, Integer)}") End Sub End Module
ID: 324
using uCalcSoftware;
var uc = new uCalc();
// Internal Test: Verify error state is cleared
Console.WriteLine("--- Testing Error State Lifecycle ---");
// 1. Trigger a division-by-zero error.
uc.Error.TrapOnDivideByZero = true;
uc.EvalStr("1 / 0");
Console.WriteLine($"Message after 1/0: '{uc.Error.Message}'");
Console.WriteLine($"Error number is not None: {uc.Error.Code != ErrorCode.None}");
// 2. Perform a successful operation, which should clear the previous error state.
uc.EvalStr("1 + 1");
// 3. Verify the error message and number have been reset.
Console.WriteLine($"Message after successful op: '{uc.Error.Message}'");
Console.WriteLine($"Error number is now None: {uc.Error.Code == ErrorCode.None}");
--- Testing Error State Lifecycle ---
Message after 1/0: 'Division by 0'
Error number is not None: True
Message after successful op: 'No error'
Error number is now None: True using uCalcSoftware; var uc = new uCalc(); // Internal Test: Verify error state is cleared Console.WriteLine("--- Testing Error State Lifecycle ---"); // 1. Trigger a division-by-zero error. uc.Error.TrapOnDivideByZero = true; uc.EvalStr("1 / 0"); Console.WriteLine($"Message after 1/0: '{uc.Error.Message}'"); Console.WriteLine($"Error number is not None: {uc.Error.Code != ErrorCode.None}"); // 2. Perform a successful operation, which should clear the previous error state. uc.EvalStr("1 + 1"); // 3. Verify the error message and number have been reset. Console.WriteLine($"Message after successful op: '{uc.Error.Message}'"); Console.WriteLine($"Error number is now None: {uc.Error.Code == ErrorCode.None}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
#define tf(IsTrue) ((IsTrue) ? "True" : "False")
int main() {
uCalc uc;
// Internal Test: Verify error state is cleared
cout << "--- Testing Error State Lifecycle ---" << endl;
// 1. Trigger a division-by-zero error.
uc.Error().TrapOnDivideByZero(true);
uc.EvalStr("1 / 0");
cout << "Message after 1/0: '" << uc.Error().Message() << "'" << endl;
cout << "Error number is not None: " << tf(uc.Error().Code() != ErrorCode::None) << endl;
// 2. Perform a successful operation, which should clear the previous error state.
uc.EvalStr("1 + 1");
// 3. Verify the error message and number have been reset.
cout << "Message after successful op: '" << uc.Error().Message() << "'" << endl;
cout << "Error number is now None: " << tf(uc.Error().Code() == ErrorCode::None) << endl;
}
--- Testing Error State Lifecycle ---
Message after 1/0: 'Division by 0'
Error number is not None: True
Message after successful op: 'No error'
Error number is now None: True #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; #define tf(IsTrue) ((IsTrue) ? "True" : "False") int main() { uCalc uc; // Internal Test: Verify error state is cleared cout << "--- Testing Error State Lifecycle ---" << endl; // 1. Trigger a division-by-zero error. uc.Error().TrapOnDivideByZero(true); uc.EvalStr("1 / 0"); cout << "Message after 1/0: '" << uc.Error().Message() << "'" << endl; cout << "Error number is not None: " << tf(uc.Error().Code() != ErrorCode::None) << endl; // 2. Perform a successful operation, which should clear the previous error state. uc.EvalStr("1 + 1"); // 3. Verify the error message and number have been reset. cout << "Message after successful op: '" << uc.Error().Message() << "'" << endl; cout << "Error number is now None: " << tf(uc.Error().Code() == ErrorCode::None) << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Internal Test: Verify error state is cleared
Console.WriteLine("--- Testing Error State Lifecycle ---")
'// 1. Trigger a division-by-zero error.
uc.Error.TrapOnDivideByZero = true
uc.EvalStr("1 / 0")
Console.WriteLine($"Message after 1/0: '{uc.Error.Message}'")
Console.WriteLine($"Error number is not None: {uc.Error.Code <> ErrorCode.None}")
'// 2. Perform a successful operation, which should clear the previous error state.
uc.EvalStr("1 + 1")
'// 3. Verify the error message and number have been reset.
Console.WriteLine($"Message after successful op: '{uc.Error.Message}'")
Console.WriteLine($"Error number is now None: {uc.Error.Code = ErrorCode.None}")
End Sub
End Module
--- Testing Error State Lifecycle ---
Message after 1/0: 'Division by 0'
Error number is not None: True
Message after successful op: 'No error'
Error number is now None: True Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Internal Test: Verify error state is cleared Console.WriteLine("--- Testing Error State Lifecycle ---") '// 1. Trigger a division-by-zero error. uc.Error.TrapOnDivideByZero = true uc.EvalStr("1 / 0") Console.WriteLine($"Message after 1/0: '{uc.Error.Message}'") Console.WriteLine($"Error number is not None: {uc.Error.Code <> ErrorCode.None}") '// 2. Perform a successful operation, which should clear the previous error state. uc.EvalStr("1 + 1") '// 3. Verify the error message and number have been reset. Console.WriteLine($"Message after successful op: '{uc.Error.Message}'") Console.WriteLine($"Error number is now None: {uc.Error.Code = ErrorCode.None}") End Sub End Module
ID: 329
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 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"));
#include
#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 #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; }
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 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
ID: 54
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 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"));
#include
#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 #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; }
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 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
ID: 405
using uCalcSoftware;
var uc = new uCalc();
// Enable only the division by zero error
uc.Error.TrapOnDivideByZero = true;
// This should now raise a uCalc error
Console.WriteLine($"Test 1 (Div by Zero): {uc.EvalStr("1/0")}");
// This should still return 'inf' by default, as we didn't enable overflow errors
Console.WriteLine($"Test 2 (Overflow): {uc.EvalStr("1e308 * 2")}");
// For comparison, enable overflow errors as well
uc.Error.TrapOnOverflow = true;
Console.WriteLine($"Test 3 (Overflow with error): {uc.EvalStr("1e308 * 2")}");
Test 1 (Div by Zero): Division by 0
Test 2 (Overflow): inf
Test 3 (Overflow with error): Floating point overflow using uCalcSoftware; var uc = new uCalc(); // Enable only the division by zero error uc.Error.TrapOnDivideByZero = true; // This should now raise a uCalc error Console.WriteLine($"Test 1 (Div by Zero): {uc.EvalStr("1/0")}"); // This should still return 'inf' by default, as we didn't enable overflow errors Console.WriteLine($"Test 2 (Overflow): {uc.EvalStr("1e308 * 2")}"); // For comparison, enable overflow errors as well uc.Error.TrapOnOverflow = true; Console.WriteLine($"Test 3 (Overflow with error): {uc.EvalStr("1e308 * 2")}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// Enable only the division by zero error
uc.Error().TrapOnDivideByZero(true);
// This should now raise a uCalc error
cout << "Test 1 (Div by Zero): " << uc.EvalStr("1/0") << endl;
// This should still return 'inf' by default, as we didn't enable overflow errors
cout << "Test 2 (Overflow): " << uc.EvalStr("1e308 * 2") << endl;
// For comparison, enable overflow errors as well
uc.Error().TrapOnOverflow(true);
cout << "Test 3 (Overflow with error): " << uc.EvalStr("1e308 * 2") << endl;
}
Test 1 (Div by Zero): Division by 0
Test 2 (Overflow): inf
Test 3 (Overflow with error): Floating point overflow #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Enable only the division by zero error uc.Error().TrapOnDivideByZero(true); // This should now raise a uCalc error cout << "Test 1 (Div by Zero): " << uc.EvalStr("1/0") << endl; // This should still return 'inf' by default, as we didn't enable overflow errors cout << "Test 2 (Overflow): " << uc.EvalStr("1e308 * 2") << endl; // For comparison, enable overflow errors as well uc.Error().TrapOnOverflow(true); cout << "Test 3 (Overflow with error): " << uc.EvalStr("1e308 * 2") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Enable only the division by zero error
uc.Error.TrapOnDivideByZero = true
'// This should now raise a uCalc error
Console.WriteLine($"Test 1 (Div by Zero): {uc.EvalStr("1/0")}")
'// This should still return 'inf' by default, as we didn't enable overflow errors
Console.WriteLine($"Test 2 (Overflow): {uc.EvalStr("1e308 * 2")}")
'// For comparison, enable overflow errors as well
uc.Error.TrapOnOverflow = true
Console.WriteLine($"Test 3 (Overflow with error): {uc.EvalStr("1e308 * 2")}")
End Sub
End Module
Test 1 (Div by Zero): Division by 0
Test 2 (Overflow): inf
Test 3 (Overflow with error): Floating point overflow Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Enable only the division by zero error uc.Error.TrapOnDivideByZero = true '// This should now raise a uCalc error Console.WriteLine($"Test 1 (Div by Zero): {uc.EvalStr("1/0")}") '// This should still return 'inf' by default, as we didn't enable overflow errors Console.WriteLine($"Test 2 (Overflow): {uc.EvalStr("1e308 * 2")}") '// For comparison, enable overflow errors as well uc.Error.TrapOnOverflow = true Console.WriteLine($"Test 3 (Overflow with error): {uc.EvalStr("1e308 * 2")}") End Sub End Module
ID: 403
using uCalcSoftware;
var uc = new uCalc();
// Default behavior: returns infinity
Console.WriteLine($"Default: {uc.EvalStr("1/0")}");
// Enable error raising
uc.Error.TrapOnDivideByZero = true;
Console.WriteLine($"Error Enabled: {uc.EvalStr("1/0")}");
// Disable error raising
uc.Error.TrapOnDivideByZero = false;
Console.WriteLine($"Error Disabled: {uc.EvalStr("1/0")}");
Default: inf
Error Enabled: Division by 0
Error Disabled: inf using uCalcSoftware; var uc = new uCalc(); // Default behavior: returns infinity Console.WriteLine($"Default: {uc.EvalStr("1/0")}"); // Enable error raising uc.Error.TrapOnDivideByZero = true; Console.WriteLine($"Error Enabled: {uc.EvalStr("1/0")}"); // Disable error raising uc.Error.TrapOnDivideByZero = false; Console.WriteLine($"Error Disabled: {uc.EvalStr("1/0")}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// Default behavior: returns infinity
cout << "Default: " << uc.EvalStr("1/0") << endl;
// Enable error raising
uc.Error().TrapOnDivideByZero(true);
cout << "Error Enabled: " << uc.EvalStr("1/0") << endl;
// Disable error raising
uc.Error().TrapOnDivideByZero(false);
cout << "Error Disabled: " << uc.EvalStr("1/0") << endl;
}
Default: inf
Error Enabled: Division by 0
Error Disabled: inf #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Default behavior: returns infinity cout << "Default: " << uc.EvalStr("1/0") << endl; // Enable error raising uc.Error().TrapOnDivideByZero(true); cout << "Error Enabled: " << uc.EvalStr("1/0") << endl; // Disable error raising uc.Error().TrapOnDivideByZero(false); cout << "Error Disabled: " << uc.EvalStr("1/0") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Default behavior: returns infinity
Console.WriteLine($"Default: {uc.EvalStr("1/0")}")
'// Enable error raising
uc.Error.TrapOnDivideByZero = true
Console.WriteLine($"Error Enabled: {uc.EvalStr("1/0")}")
'// Disable error raising
uc.Error.TrapOnDivideByZero = false
Console.WriteLine($"Error Disabled: {uc.EvalStr("1/0")}")
End Sub
End Module
Default: inf
Error Enabled: Division by 0
Error Disabled: inf Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Default behavior: returns infinity Console.WriteLine($"Default: {uc.EvalStr("1/0")}") '// Enable error raising uc.Error.TrapOnDivideByZero = true Console.WriteLine($"Error Enabled: {uc.EvalStr("1/0")}") '// Disable error raising uc.Error.TrapOnDivideByZero = false Console.WriteLine($"Error Disabled: {uc.EvalStr("1/0")}") End Sub End Module
ID: 80
using uCalcSoftware;
var uc = new uCalc();
Console.WriteLine(uc.EvalStr("1/0"));
uc.Error.TrapOnDivideByZero = true;
Console.WriteLine(uc.EvalStr("1/0"));
Console.WriteLine(uc.EvalStr("Sqrt(-1)"));
uc.Error.TrapOnInvalid = true;
Console.WriteLine(uc.EvalStr("Sqrt(-1)"));
Console.WriteLine(uc.EvalStr("5*10^308"));
uc.Error.TrapOnOverflow = true;
Console.WriteLine(uc.EvalStr("5*10^308"));
Console.WriteLine(uc.EvalStr("10^-308/10000"));
uc.Error.TrapOnUnderflow = true;
Console.WriteLine(uc.EvalStr("10^-308/10000"));
inf
Division by 0
nan
Invalid operation
inf
Floating point overflow
0
Floating point underflow using uCalcSoftware; var uc = new uCalc(); Console.WriteLine(uc.EvalStr("1/0")); uc.Error.TrapOnDivideByZero = true; Console.WriteLine(uc.EvalStr("1/0")); Console.WriteLine(uc.EvalStr("Sqrt(-1)")); uc.Error.TrapOnInvalid = true; Console.WriteLine(uc.EvalStr("Sqrt(-1)")); Console.WriteLine(uc.EvalStr("5*10^308")); uc.Error.TrapOnOverflow = true; Console.WriteLine(uc.EvalStr("5*10^308")); Console.WriteLine(uc.EvalStr("10^-308/10000")); uc.Error.TrapOnUnderflow = true; Console.WriteLine(uc.EvalStr("10^-308/10000"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
cout << uc.EvalStr("1/0") << endl;
uc.Error().TrapOnDivideByZero(true);
cout << uc.EvalStr("1/0") << endl;
cout << uc.EvalStr("Sqrt(-1)") << endl;
uc.Error().TrapOnInvalid(true);
cout << uc.EvalStr("Sqrt(-1)") << endl;
cout << uc.EvalStr("5*10^308") << endl;
uc.Error().TrapOnOverflow(true);
cout << uc.EvalStr("5*10^308") << endl;
cout << uc.EvalStr("10^-308/10000") << endl;
uc.Error().TrapOnUnderflow(true);
cout << uc.EvalStr("10^-308/10000") << endl;
}
inf
Division by 0
nan
Invalid operation
inf
Floating point overflow
0
Floating point underflow #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; cout << uc.EvalStr("1/0") << endl; uc.Error().TrapOnDivideByZero(true); cout << uc.EvalStr("1/0") << endl; cout << uc.EvalStr("Sqrt(-1)") << endl; uc.Error().TrapOnInvalid(true); cout << uc.EvalStr("Sqrt(-1)") << endl; cout << uc.EvalStr("5*10^308") << endl; uc.Error().TrapOnOverflow(true); cout << uc.EvalStr("5*10^308") << endl; cout << uc.EvalStr("10^-308/10000") << endl; uc.Error().TrapOnUnderflow(true); cout << uc.EvalStr("10^-308/10000") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Console.WriteLine(uc.EvalStr("1/0"))
uc.Error.TrapOnDivideByZero = true
Console.WriteLine(uc.EvalStr("1/0"))
Console.WriteLine(uc.EvalStr("Sqrt(-1)"))
uc.Error.TrapOnInvalid = true
Console.WriteLine(uc.EvalStr("Sqrt(-1)"))
Console.WriteLine(uc.EvalStr("5*10^308"))
uc.Error.TrapOnOverflow = true
Console.WriteLine(uc.EvalStr("5*10^308"))
Console.WriteLine(uc.EvalStr("10^-308/10000"))
uc.Error.TrapOnUnderflow = true
Console.WriteLine(uc.EvalStr("10^-308/10000"))
End Sub
End Module
inf
Division by 0
nan
Invalid operation
inf
Floating point overflow
0
Floating point underflow Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Console.WriteLine(uc.EvalStr("1/0")) uc.Error.TrapOnDivideByZero = true Console.WriteLine(uc.EvalStr("1/0")) Console.WriteLine(uc.EvalStr("Sqrt(-1)")) uc.Error.TrapOnInvalid = true Console.WriteLine(uc.EvalStr("Sqrt(-1)")) Console.WriteLine(uc.EvalStr("5*10^308")) uc.Error.TrapOnOverflow = true Console.WriteLine(uc.EvalStr("5*10^308")) Console.WriteLine(uc.EvalStr("10^-308/10000")) uc.Error.TrapOnUnderflow = true Console.WriteLine(uc.EvalStr("10^-308/10000")) End Sub End Module
ID: 74
using uCalcSoftware;
var uc = new uCalc();
Console.WriteLine(uc.Error.FloatingPointErrorsToTrap);
Console.WriteLine(uc.EvalStr("1/0"));
Console.WriteLine(uc.EvalStr("0/0"));
Console.WriteLine(uc.EvalStr("5*10^308"));
Console.WriteLine(uc.EvalStr("10^-308/10000"));
Console.WriteLine("--- Raise Div-by-0 ---");
uc.Error.FloatingPointErrorsToTrap = (int)ErrorCode.FloatDivisionByZero;
Console.WriteLine(uc.Error.FloatingPointErrorsToTrap);
Console.WriteLine(uc.EvalStr("1/0"));
Console.WriteLine(uc.EvalStr("0/0"));
Console.WriteLine(uc.EvalStr("5*10^308"));
Console.WriteLine(uc.EvalStr("10^-308/10000"));
Console.WriteLine("--- Raise overflow ---");
uc.Error.FloatingPointErrorsToTrap = (int)ErrorCode.FloatOverflow;
Console.WriteLine(uc.Error.FloatingPointErrorsToTrap);
Console.WriteLine(uc.EvalStr("1/0"));
Console.WriteLine(uc.EvalStr("0/0"));
Console.WriteLine(uc.EvalStr("5*10^308"));
Console.WriteLine(uc.EvalStr("10^-308/10000"));
Console.WriteLine("--- Raise invalid & underflow ---");
uc.Error.SetFloatingPointErrorsToTrap(ErrorCode.FloatInvalid, ErrorCode.FloatUnderflow);
Console.WriteLine(uc.Error.FloatingPointErrorsToTrap); // ErrorCode::FloatInvalid + ErrorCode::FloatUnderflow
Console.WriteLine(uc.EvalStr("1/0"));
Console.WriteLine(uc.EvalStr("0/0"));
Console.WriteLine(uc.EvalStr("5*10^308"));
Console.WriteLine(uc.EvalStr("10^-308/10000"));
0
inf
nan
inf
0
--- Raise Div-by-0 ---
8
Division by 0
nan
inf
0
--- Raise overflow ---
4
Floating point overflow
nan
Floating point overflow
0
--- Raise invalid & underflow ---
18
inf
Invalid operation
inf
Floating point underflow using uCalcSoftware; var uc = new uCalc(); Console.WriteLine(uc.Error.FloatingPointErrorsToTrap); Console.WriteLine(uc.EvalStr("1/0")); Console.WriteLine(uc.EvalStr("0/0")); Console.WriteLine(uc.EvalStr("5*10^308")); Console.WriteLine(uc.EvalStr("10^-308/10000")); Console.WriteLine("--- Raise Div-by-0 ---"); uc.Error.FloatingPointErrorsToTrap = (int)ErrorCode.FloatDivisionByZero; Console.WriteLine(uc.Error.FloatingPointErrorsToTrap); Console.WriteLine(uc.EvalStr("1/0")); Console.WriteLine(uc.EvalStr("0/0")); Console.WriteLine(uc.EvalStr("5*10^308")); Console.WriteLine(uc.EvalStr("10^-308/10000")); Console.WriteLine("--- Raise overflow ---"); uc.Error.FloatingPointErrorsToTrap = (int)ErrorCode.FloatOverflow; Console.WriteLine(uc.Error.FloatingPointErrorsToTrap); Console.WriteLine(uc.EvalStr("1/0")); Console.WriteLine(uc.EvalStr("0/0")); Console.WriteLine(uc.EvalStr("5*10^308")); Console.WriteLine(uc.EvalStr("10^-308/10000")); Console.WriteLine("--- Raise invalid & underflow ---"); uc.Error.SetFloatingPointErrorsToTrap(ErrorCode.FloatInvalid, ErrorCode.FloatUnderflow); Console.WriteLine(uc.Error.FloatingPointErrorsToTrap); // ErrorCode::FloatInvalid + ErrorCode::FloatUnderflow Console.WriteLine(uc.EvalStr("1/0")); Console.WriteLine(uc.EvalStr("0/0")); Console.WriteLine(uc.EvalStr("5*10^308")); Console.WriteLine(uc.EvalStr("10^-308/10000"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
cout << uc.Error().FloatingPointErrorsToTrap() << endl;
cout << uc.EvalStr("1/0") << endl;
cout << uc.EvalStr("0/0") << endl;
cout << uc.EvalStr("5*10^308") << endl;
cout << uc.EvalStr("10^-308/10000") << endl;
cout << "--- Raise Div-by-0 ---" << endl;
uc.Error().FloatingPointErrorsToTrap((int)ErrorCode::FloatDivisionByZero);
cout << uc.Error().FloatingPointErrorsToTrap() << endl;
cout << uc.EvalStr("1/0") << endl;
cout << uc.EvalStr("0/0") << endl;
cout << uc.EvalStr("5*10^308") << endl;
cout << uc.EvalStr("10^-308/10000") << endl;
cout << "--- Raise overflow ---" << endl;
uc.Error().FloatingPointErrorsToTrap((int)ErrorCode::FloatOverflow);
cout << uc.Error().FloatingPointErrorsToTrap() << endl;
cout << uc.EvalStr("1/0") << endl;
cout << uc.EvalStr("0/0") << endl;
cout << uc.EvalStr("5*10^308") << endl;
cout << uc.EvalStr("10^-308/10000") << endl;
cout << "--- Raise invalid & underflow ---" << endl;
uc.Error().SetFloatingPointErrorsToTrap(ErrorCode::FloatInvalid, ErrorCode::FloatUnderflow);
cout << uc.Error().FloatingPointErrorsToTrap() << endl; // ErrorCode::FloatInvalid + ErrorCode::FloatUnderflow
cout << uc.EvalStr("1/0") << endl;
cout << uc.EvalStr("0/0") << endl;
cout << uc.EvalStr("5*10^308") << endl;
cout << uc.EvalStr("10^-308/10000") << endl;
}
0
inf
nan
inf
0
--- Raise Div-by-0 ---
8
Division by 0
nan
inf
0
--- Raise overflow ---
4
Floating point overflow
nan
Floating point overflow
0
--- Raise invalid & underflow ---
18
inf
Invalid operation
inf
Floating point underflow #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; cout << uc.Error().FloatingPointErrorsToTrap() << endl; cout << uc.EvalStr("1/0") << endl; cout << uc.EvalStr("0/0") << endl; cout << uc.EvalStr("5*10^308") << endl; cout << uc.EvalStr("10^-308/10000") << endl; cout << "--- Raise Div-by-0 ---" << endl; uc.Error().FloatingPointErrorsToTrap((int)ErrorCode::FloatDivisionByZero); cout << uc.Error().FloatingPointErrorsToTrap() << endl; cout << uc.EvalStr("1/0") << endl; cout << uc.EvalStr("0/0") << endl; cout << uc.EvalStr("5*10^308") << endl; cout << uc.EvalStr("10^-308/10000") << endl; cout << "--- Raise overflow ---" << endl; uc.Error().FloatingPointErrorsToTrap((int)ErrorCode::FloatOverflow); cout << uc.Error().FloatingPointErrorsToTrap() << endl; cout << uc.EvalStr("1/0") << endl; cout << uc.EvalStr("0/0") << endl; cout << uc.EvalStr("5*10^308") << endl; cout << uc.EvalStr("10^-308/10000") << endl; cout << "--- Raise invalid & underflow ---" << endl; uc.Error().SetFloatingPointErrorsToTrap(ErrorCode::FloatInvalid, ErrorCode::FloatUnderflow); cout << uc.Error().FloatingPointErrorsToTrap() << endl; // ErrorCode::FloatInvalid + ErrorCode::FloatUnderflow cout << uc.EvalStr("1/0") << endl; cout << uc.EvalStr("0/0") << endl; cout << uc.EvalStr("5*10^308") << endl; cout << uc.EvalStr("10^-308/10000") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Console.WriteLine(uc.Error.FloatingPointErrorsToTrap)
Console.WriteLine(uc.EvalStr("1/0"))
Console.WriteLine(uc.EvalStr("0/0"))
Console.WriteLine(uc.EvalStr("5*10^308"))
Console.WriteLine(uc.EvalStr("10^-308/10000"))
Console.WriteLine("--- Raise Div-by-0 ---")
uc.Error.FloatingPointErrorsToTrap = CInt(ErrorCode.FloatDivisionByZero)
Console.WriteLine(uc.Error.FloatingPointErrorsToTrap)
Console.WriteLine(uc.EvalStr("1/0"))
Console.WriteLine(uc.EvalStr("0/0"))
Console.WriteLine(uc.EvalStr("5*10^308"))
Console.WriteLine(uc.EvalStr("10^-308/10000"))
Console.WriteLine("--- Raise overflow ---")
uc.Error.FloatingPointErrorsToTrap = CInt(ErrorCode.FloatOverflow)
Console.WriteLine(uc.Error.FloatingPointErrorsToTrap)
Console.WriteLine(uc.EvalStr("1/0"))
Console.WriteLine(uc.EvalStr("0/0"))
Console.WriteLine(uc.EvalStr("5*10^308"))
Console.WriteLine(uc.EvalStr("10^-308/10000"))
Console.WriteLine("--- Raise invalid & underflow ---")
uc.Error.SetFloatingPointErrorsToTrap(ErrorCode.FloatInvalid, ErrorCode.FloatUnderflow)
Console.WriteLine(uc.Error.FloatingPointErrorsToTrap) '// ErrorCode::FloatInvalid + ErrorCode::FloatUnderflow
Console.WriteLine(uc.EvalStr("1/0"))
Console.WriteLine(uc.EvalStr("0/0"))
Console.WriteLine(uc.EvalStr("5*10^308"))
Console.WriteLine(uc.EvalStr("10^-308/10000"))
End Sub
End Module
0
inf
nan
inf
0
--- Raise Div-by-0 ---
8
Division by 0
nan
inf
0
--- Raise overflow ---
4
Floating point overflow
nan
Floating point overflow
0
--- Raise invalid & underflow ---
18
inf
Invalid operation
inf
Floating point underflow Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Console.WriteLine(uc.Error.FloatingPointErrorsToTrap) Console.WriteLine(uc.EvalStr("1/0")) Console.WriteLine(uc.EvalStr("0/0")) Console.WriteLine(uc.EvalStr("5*10^308")) Console.WriteLine(uc.EvalStr("10^-308/10000")) Console.WriteLine("--- Raise Div-by-0 ---") uc.Error.FloatingPointErrorsToTrap = CInt(ErrorCode.FloatDivisionByZero) Console.WriteLine(uc.Error.FloatingPointErrorsToTrap) Console.WriteLine(uc.EvalStr("1/0")) Console.WriteLine(uc.EvalStr("0/0")) Console.WriteLine(uc.EvalStr("5*10^308")) Console.WriteLine(uc.EvalStr("10^-308/10000")) Console.WriteLine("--- Raise overflow ---") uc.Error.FloatingPointErrorsToTrap = CInt(ErrorCode.FloatOverflow) Console.WriteLine(uc.Error.FloatingPointErrorsToTrap) Console.WriteLine(uc.EvalStr("1/0")) Console.WriteLine(uc.EvalStr("0/0")) Console.WriteLine(uc.EvalStr("5*10^308")) Console.WriteLine(uc.EvalStr("10^-308/10000")) Console.WriteLine("--- Raise invalid & underflow ---") uc.Error.SetFloatingPointErrorsToTrap(ErrorCode.FloatInvalid, ErrorCode.FloatUnderflow) Console.WriteLine(uc.Error.FloatingPointErrorsToTrap) '// ErrorCode::FloatInvalid + ErrorCode::FloatUnderflow Console.WriteLine(uc.EvalStr("1/0")) Console.WriteLine(uc.EvalStr("0/0")) Console.WriteLine(uc.EvalStr("5*10^308")) Console.WriteLine(uc.EvalStr("10^-308/10000")) End Sub End Module
ID: 258
using uCalcSoftware;
var uc = new uCalc();
static void LogAndResume(Handle_uCalc h) {
var uc = new uCalc(h);
Console.WriteLine($"Logged error: {uc.Error.Message}");
uc.Error.Response = ErrorHandlerResponse.Resume;
}
uc.Error.TrapOnDivideByZero = true;
uc.Error.AddHandler(LogAndResume);
Console.WriteLine("Start");
var Result = uc.Eval("5/0"); // Division by zero
Console.WriteLine("End");
Start
Logged error: Division by 0
End using uCalcSoftware; var uc = new uCalc(); static void LogAndResume(Handle_uCalc h) { var uc = new uCalc(h); Console.WriteLine($"Logged error: {uc.Error.Message}"); uc.Error.Response = ErrorHandlerResponse.Resume; } uc.Error.TrapOnDivideByZero = true; uc.Error.AddHandler(LogAndResume); Console.WriteLine("Start"); var Result = uc.Eval("5/0"); // Division by zero Console.WriteLine("End");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
void ucalc_call LogAndResume(Handle_uCalc h) {
auto uc = uCalc(h);
cout << "Logged error: " << uc.Error().Message() << endl;
uc.Error().Response(ErrorHandlerResponse::Resume);
}
int main() {
uCalc uc;
uc.Error().TrapOnDivideByZero(true);
uc.Error().AddHandler(LogAndResume);
cout << "Start" << endl;
auto Result = uc.Eval("5/0"); // Division by zero
cout << "End" << endl;
}
Start
Logged error: Division by 0
End #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; void ucalc_call LogAndResume(Handle_uCalc h) { auto uc = uCalc(h); cout << "Logged error: " << uc.Error().Message() << endl; uc.Error().Response(ErrorHandlerResponse::Resume); } int main() { uCalc uc; uc.Error().TrapOnDivideByZero(true); uc.Error().AddHandler(LogAndResume); cout << "Start" << endl; auto Result = uc.Eval("5/0"); // Division by zero cout << "End" << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub LogAndResume(ByVal h As Handle_uCalc)
Dim uc As New uCalc(h)
Console.WriteLine($"Logged error: {uc.Error.Message}")
uc.Error.Response = ErrorHandlerResponse.Resume
End Sub
Public Sub Main()
Dim uc As New uCalc()
uc.Error.TrapOnDivideByZero = true
uc.Error.AddHandler(AddressOf LogAndResume)
Console.WriteLine("Start")
Dim Result = uc.Eval("5/0") '// Division by zero
Console.WriteLine("End")
End Sub
End Module
Start
Logged error: Division by 0
End Imports System Imports uCalcSoftware Public Module Program Public Sub LogAndResume(ByVal h As Handle_uCalc) Dim uc As New uCalc(h) Console.WriteLine($"Logged error: {uc.Error.Message}") uc.Error.Response = ErrorHandlerResponse.Resume End Sub Public Sub Main() Dim uc As New uCalc() uc.Error.TrapOnDivideByZero = true uc.Error.AddHandler(AddressOf LogAndResume) Console.WriteLine("Start") Dim Result = uc.Eval("5/0") '// Division by zero Console.WriteLine("End") End Sub End Module
ID: 55
using uCalcSoftware;
var uc = new uCalc();
static void ErrorHandlerA(Handle_uCalc h) {
var uc = new uCalc(h);
Console.WriteLine("Handler A called");
}
static void ErrorHandlerB(Handle_uCalc h) {
var uc = new uCalc(h);
Console.WriteLine("Handler B called");
}
static void ErrorHandlerC(Handle_uCalc h) {
var uc = new uCalc(h);
Console.WriteLine("Handler C called");
}
static void ErrorHandlerD(Handle_uCalc h) {
var uc = new uCalc(h);
Console.WriteLine("Handler D called");
}
static void ErrorHandlerE(Handle_uCalc h) {
var uc = new uCalc(h);
Console.WriteLine("Handler E called");
}
uc.Error.AddHandler(ErrorHandlerA);
uc.Error.AddHandler(ErrorHandlerB);
uc.Error.AddHandler(ErrorHandlerC);
uc.Error.AddHandler(ErrorHandlerD, -1);
uc.Error.AddHandler(ErrorHandlerE, 3);
Console.WriteLine(uc.EvalStr("10 / "));
Handler C called
Handler B called
Handler A called
Handler E called
Handler D called
Syntax error using uCalcSoftware; var uc = new uCalc(); static void ErrorHandlerA(Handle_uCalc h) { var uc = new uCalc(h); Console.WriteLine("Handler A called"); } static void ErrorHandlerB(Handle_uCalc h) { var uc = new uCalc(h); Console.WriteLine("Handler B called"); } static void ErrorHandlerC(Handle_uCalc h) { var uc = new uCalc(h); Console.WriteLine("Handler C called"); } static void ErrorHandlerD(Handle_uCalc h) { var uc = new uCalc(h); Console.WriteLine("Handler D called"); } static void ErrorHandlerE(Handle_uCalc h) { var uc = new uCalc(h); Console.WriteLine("Handler E called"); } uc.Error.AddHandler(ErrorHandlerA); uc.Error.AddHandler(ErrorHandlerB); uc.Error.AddHandler(ErrorHandlerC); uc.Error.AddHandler(ErrorHandlerD, -1); uc.Error.AddHandler(ErrorHandlerE, 3); Console.WriteLine(uc.EvalStr("10 / "));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
void ucalc_call ErrorHandlerA(Handle_uCalc h) {
auto uc = uCalc(h);
cout << "Handler A called" << endl;
}
void ucalc_call ErrorHandlerB(Handle_uCalc h) {
auto uc = uCalc(h);
cout << "Handler B called" << endl;
}
void ucalc_call ErrorHandlerC(Handle_uCalc h) {
auto uc = uCalc(h);
cout << "Handler C called" << endl;
}
void ucalc_call ErrorHandlerD(Handle_uCalc h) {
auto uc = uCalc(h);
cout << "Handler D called" << endl;
}
void ucalc_call ErrorHandlerE(Handle_uCalc h) {
auto uc = uCalc(h);
cout << "Handler E called" << endl;
}
int main() {
uCalc uc;
uc.Error().AddHandler(ErrorHandlerA);
uc.Error().AddHandler(ErrorHandlerB);
uc.Error().AddHandler(ErrorHandlerC);
uc.Error().AddHandler(ErrorHandlerD, -1);
uc.Error().AddHandler(ErrorHandlerE, 3);
cout << uc.EvalStr("10 / ") << endl;
}
Handler C called
Handler B called
Handler A called
Handler E called
Handler D called
Syntax error #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; void ucalc_call ErrorHandlerA(Handle_uCalc h) { auto uc = uCalc(h); cout << "Handler A called" << endl; } void ucalc_call ErrorHandlerB(Handle_uCalc h) { auto uc = uCalc(h); cout << "Handler B called" << endl; } void ucalc_call ErrorHandlerC(Handle_uCalc h) { auto uc = uCalc(h); cout << "Handler C called" << endl; } void ucalc_call ErrorHandlerD(Handle_uCalc h) { auto uc = uCalc(h); cout << "Handler D called" << endl; } void ucalc_call ErrorHandlerE(Handle_uCalc h) { auto uc = uCalc(h); cout << "Handler E called" << endl; } int main() { uCalc uc; uc.Error().AddHandler(ErrorHandlerA); uc.Error().AddHandler(ErrorHandlerB); uc.Error().AddHandler(ErrorHandlerC); uc.Error().AddHandler(ErrorHandlerD, -1); uc.Error().AddHandler(ErrorHandlerE, 3); cout << uc.EvalStr("10 / ") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub ErrorHandlerA(ByVal h As Handle_uCalc)
Dim uc As New uCalc(h)
Console.WriteLine("Handler A called")
End Sub
Public Sub ErrorHandlerB(ByVal h As Handle_uCalc)
Dim uc As New uCalc(h)
Console.WriteLine("Handler B called")
End Sub
Public Sub ErrorHandlerC(ByVal h As Handle_uCalc)
Dim uc As New uCalc(h)
Console.WriteLine("Handler C called")
End Sub
Public Sub ErrorHandlerD(ByVal h As Handle_uCalc)
Dim uc As New uCalc(h)
Console.WriteLine("Handler D called")
End Sub
Public Sub ErrorHandlerE(ByVal h As Handle_uCalc)
Dim uc As New uCalc(h)
Console.WriteLine("Handler E called")
End Sub
Public Sub Main()
Dim uc As New uCalc()
uc.Error.AddHandler(AddressOf ErrorHandlerA)
uc.Error.AddHandler(AddressOf ErrorHandlerB)
uc.Error.AddHandler(AddressOf ErrorHandlerC)
uc.Error.AddHandler(AddressOf ErrorHandlerD, -1)
uc.Error.AddHandler(AddressOf ErrorHandlerE, 3)
Console.WriteLine(uc.EvalStr("10 / "))
End Sub
End Module
Handler C called
Handler B called
Handler A called
Handler E called
Handler D called
Syntax error Imports System Imports uCalcSoftware Public Module Program Public Sub ErrorHandlerA(ByVal h As Handle_uCalc) Dim uc As New uCalc(h) Console.WriteLine("Handler A called") End Sub Public Sub ErrorHandlerB(ByVal h As Handle_uCalc) Dim uc As New uCalc(h) Console.WriteLine("Handler B called") End Sub Public Sub ErrorHandlerC(ByVal h As Handle_uCalc) Dim uc As New uCalc(h) Console.WriteLine("Handler C called") End Sub Public Sub ErrorHandlerD(ByVal h As Handle_uCalc) Dim uc As New uCalc(h) Console.WriteLine("Handler D called") End Sub Public Sub ErrorHandlerE(ByVal h As Handle_uCalc) Dim uc As New uCalc(h) Console.WriteLine("Handler E called") End Sub Public Sub Main() Dim uc As New uCalc() uc.Error.AddHandler(AddressOf ErrorHandlerA) uc.Error.AddHandler(AddressOf ErrorHandlerB) uc.Error.AddHandler(AddressOf ErrorHandlerC) uc.Error.AddHandler(AddressOf ErrorHandlerD, -1) uc.Error.AddHandler(AddressOf ErrorHandlerE, 3) Console.WriteLine(uc.EvalStr("10 / ")) End Sub End Module
ID: 482
using uCalcSoftware;
var uc = new uCalc();
static void MyHandler(Handle_uCalc h) {
var uc = new uCalc(h);
// This handler just logs the error and aborts
Console.WriteLine($"Error Handler Caught: {uc.Error.Message}");
}
static void MyFunc(uCalc.Callback cb) {
// This function always fails with a custom message
cb.Error.Raise("Validation failed for input.");
}
uc.Error.AddHandler(MyHandler);
uc.DefineFunction("Validate()", MyFunc);
uc.EvalStr("Validate()"); // This call will trigger the error
Error Handler Caught: Validation failed for input. using uCalcSoftware; var uc = new uCalc(); static void MyHandler(Handle_uCalc h) { var uc = new uCalc(h); // This handler just logs the error and aborts Console.WriteLine($"Error Handler Caught: {uc.Error.Message}"); } static void MyFunc(uCalc.Callback cb) { // This function always fails with a custom message cb.Error.Raise("Validation failed for input."); } uc.Error.AddHandler(MyHandler); uc.DefineFunction("Validate()", MyFunc); uc.EvalStr("Validate()"); // This call will trigger the error
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
void ucalc_call MyHandler(Handle_uCalc h) {
auto uc = uCalc(h);
// This handler just logs the error and aborts
cout << "Error Handler Caught: " << uc.Error().Message() << endl;
}
void ucalc_call MyFunc(uCalcBase::Callback cb) {
// This function always fails with a custom message
cb.Error().Raise("Validation failed for input.");
}
int main() {
uCalc uc;
uc.Error().AddHandler(MyHandler);
uc.DefineFunction("Validate()", MyFunc);
uc.EvalStr("Validate()"); // This call will trigger the error
}
Error Handler Caught: Validation failed for input. #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; void ucalc_call MyHandler(Handle_uCalc h) { auto uc = uCalc(h); // This handler just logs the error and aborts cout << "Error Handler Caught: " << uc.Error().Message() << endl; } void ucalc_call MyFunc(uCalcBase::Callback cb) { // This function always fails with a custom message cb.Error().Raise("Validation failed for input."); } int main() { uCalc uc; uc.Error().AddHandler(MyHandler); uc.DefineFunction("Validate()", MyFunc); uc.EvalStr("Validate()"); // This call will trigger the error }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub MyHandler(ByVal h As Handle_uCalc)
Dim uc As New uCalc(h)
'// This handler just logs the error and aborts
Console.WriteLine($"Error Handler Caught: {uc.Error.Message}")
End Sub
Public Sub MyFunc(ByVal cb As uCalc.Callback)
'// This function always fails with a custom message
cb.Error.Raise("Validation failed for input.")
End Sub
Public Sub Main()
Dim uc As New uCalc()
uc.Error.AddHandler(AddressOf MyHandler)
uc.DefineFunction("Validate()", AddressOf MyFunc)
uc.EvalStr("Validate()") '// This call will trigger the error
End Sub
End Module
Error Handler Caught: Validation failed for input. Imports System Imports uCalcSoftware Public Module Program Public Sub MyHandler(ByVal h As Handle_uCalc) Dim uc As New uCalc(h) '// This handler just logs the error and aborts Console.WriteLine($"Error Handler Caught: {uc.Error.Message}") End Sub Public Sub MyFunc(ByVal cb As uCalc.Callback) '// This function always fails with a custom message cb.Error.Raise("Validation failed for input.") End Sub Public Sub Main() Dim uc As New uCalc() uc.Error.AddHandler(AddressOf MyHandler) uc.DefineFunction("Validate()", AddressOf MyFunc) uc.EvalStr("Validate()") '// This call will trigger the error End Sub End Module
ID: 1190
using uCalcSoftware;
var uc = new uCalc();
// This handler automatically defines variables when they are first used.
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) {
Console.WriteLine($"Handler: '{uc.Error.Symbol}' is undefined. Defining it now.");
uc.DefineVariable(uc.Error.Symbol);
// Tell the engine to resume the operation
uc.Error.Response = ErrorHandlerResponse.Resume;
}
}
uc.Error.AddHandler(AutoDefineHandler);
// 'my_var' doesn't exist yet, but the handler will create it.
var result = uc.EvalStr("my_var = 100; my_var = my_var * 2");
Console.WriteLine($"Final result: {result}");
Handler: 'my_var' is undefined. Defining it now.
Final result: 200 using uCalcSoftware; var uc = new uCalc(); // This handler automatically defines variables when they are first used. 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) { Console.WriteLine($"Handler: '{uc.Error.Symbol}' is undefined. Defining it now."); uc.DefineVariable(uc.Error.Symbol); // Tell the engine to resume the operation uc.Error.Response = ErrorHandlerResponse.Resume; } } uc.Error.AddHandler(AutoDefineHandler); // 'my_var' doesn't exist yet, but the handler will create it. var result = uc.EvalStr("my_var = 100; my_var = my_var * 2"); Console.WriteLine($"Final result: {result}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
// This handler automatically defines variables when they are first used.
void ucalc_call AutoDefineHandler(Handle_uCalc h) {
auto uc = uCalc(h);
// Check if the error is specifically an undefined identifier
if (uc.Error().Code() == ErrorCode::Undefined_Identifier) {
cout << "Handler: '" << uc.Error().Symbol() << "' is undefined. Defining it now." << endl;
uc.DefineVariable(uc.Error().Symbol());
// Tell the engine to resume the operation
uc.Error().Response(ErrorHandlerResponse::Resume);
}
}
int main() {
uCalc uc;
uc.Error().AddHandler(AutoDefineHandler);
// 'my_var' doesn't exist yet, but the handler will create it.
auto result = uc.EvalStr("my_var = 100; my_var = my_var * 2");
cout << "Final result: " << result << endl;
}
Handler: 'my_var' is undefined. Defining it now.
Final result: 200 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; // This handler automatically defines variables when they are first used. void ucalc_call AutoDefineHandler(Handle_uCalc h) { auto uc = uCalc(h); // Check if the error is specifically an undefined identifier if (uc.Error().Code() == ErrorCode::Undefined_Identifier) { cout << "Handler: '" << uc.Error().Symbol() << "' is undefined. Defining it now." << endl; uc.DefineVariable(uc.Error().Symbol()); // Tell the engine to resume the operation uc.Error().Response(ErrorHandlerResponse::Resume); } } int main() { uCalc uc; uc.Error().AddHandler(AutoDefineHandler); // 'my_var' doesn't exist yet, but the handler will create it. auto result = uc.EvalStr("my_var = 100; my_var = my_var * 2"); cout << "Final result: " << result << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
'// This handler automatically defines variables when they are first used.
Public Sub AutoDefineHandler(ByVal h As Handle_uCalc)
Dim uc As New uCalc(h)
'// Check if the error is specifically an undefined identifier
If uc.Error.Code = ErrorCode.Undefined_Identifier Then
Console.WriteLine($"Handler: '{uc.Error.Symbol}' is undefined. Defining it now.")
uc.DefineVariable(uc.Error.Symbol)
'// Tell the engine to resume the operation
uc.Error.Response = ErrorHandlerResponse.Resume
End If
End Sub
Public Sub Main()
Dim uc As New uCalc()
uc.Error.AddHandler(AddressOf AutoDefineHandler)
'// 'my_var' doesn't exist yet, but the handler will create it.
Dim result = uc.EvalStr("my_var = 100; my_var = my_var * 2")
Console.WriteLine($"Final result: {result}")
End Sub
End Module
Handler: 'my_var' is undefined. Defining it now.
Final result: 200 Imports System Imports uCalcSoftware Public Module Program '// This handler automatically defines variables when they are first used. Public Sub AutoDefineHandler(ByVal h As Handle_uCalc) Dim uc As New uCalc(h) '// Check if the error is specifically an undefined identifier If uc.Error.Code = ErrorCode.Undefined_Identifier Then Console.WriteLine($"Handler: '{uc.Error.Symbol}' is undefined. Defining it now.") uc.DefineVariable(uc.Error.Symbol) '// Tell the engine to resume the operation uc.Error.Response = ErrorHandlerResponse.Resume End If End Sub Public Sub Main() Dim uc As New uCalc() uc.Error.AddHandler(AddressOf AutoDefineHandler) '// 'my_var' doesn't exist yet, but the handler will create it. Dim result = uc.EvalStr("my_var = 100; my_var = my_var * 2") Console.WriteLine($"Final result: {result}") End Sub End Module