Imports System
Imports uCalcSoftware
Public Module Program
   
   Public Sub MyErrorHandler(ByVal h As Handle_uCalc)
      Dim uc As New uCalc(h)
      Console.WriteLine("--- Error Handler Caught ---")
      Console.WriteLine($"  Code: {CInt(uc.Error.Code)}")
      Console.WriteLine($"  Message: {uc.Error.Message}")
      '// Abort is the default response, no need to set it.
   End Sub
   
   Public Sub Main()
      Dim uc As New uCalc()
      '// Register the custom error handler
      uc.Error.AddHandler(AddressOf MyErrorHandler)
      
      '// Configure the engine to raise an error on overflow
      uc.Error.TrapOnOverflow = true
      
      '// This evaluation will now be intercepted by our handler
      Console.WriteLine("Evaluating expression '1e999'...")
      uc.EvalStr("1e999") '// This triggers the callback
      Console.WriteLine("Evaluation finished.")
   End Sub
End Module