Checking the error code for a simple syntax error using a callback.

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
				
					#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;
}
				
			
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
				
			
Caught Error Code: 257
This was a syntax error.
Syntax error