Capturing both parsing-stage and evaluation-stage errors to see how ErrorLocation behaves differently.
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