ErrorResponseMethod

Applies to:uCalc Transform
Class:uCalc
Sets the error response for an error handler
Syntax
ErrorResponse(Response)
Parameters
Response
Indicates what should happen now that an error is raised
Returns
Nothing
Remarks
When an error is raised, you have the option of aborting the rest of the option (which is the default option) , or you may correct the problem, and then resume the operation. Or you may perform an action, and than raise the error again for a subsequent error handle to take care of.

This method can only be called from within a callback of an error handler routine definined with AddErrorHandler. The options to use can be found at ErrorHandlerResponseEnum.

Example 1: Adding error handlers

Sub ErrorHandlerTestCB(ByVal ucPtr As IntPtr)
   Dim ucc As New uCalc(ucPtr)
   Console.WriteLine("An error has occured!")
   Console.Write("Error #: "): Console.WriteLine(ucc.ErrorNumber())
   Console.WriteLine("Error Message: " + ucc.ErrorMessage())
   Console.WriteLine("Error Symbol: " + ucc.ErrorSymbol())
   Console.WriteLine("Error Location: " + ucc.ErrorLocation())
   Console.WriteLine("Error Expression: " + ucc.ErrorExpression())
End Sub

Sub AutoVariableDefCB(ByVal ucPtr As IntPtr)
   Dim ucc As New uCalc(ucPtr)
   if ucc.ErrorNumber() = ErrorNumberEnum.Err_Undefined_Identifier Then 
      ucc.DefineVariable(ucc.ErrorSymbol())
      ucc.ErrorResponse(ErrorHandlerResponseEnum.ErrorResume)
   End if
End Sub

Sub ErrorHandler_()' +++ example also for 2nd arg
   uc.AddErrorHandler(uc.PinAddr(AddressOf ErrorHandlerTestCB))
   uc.AddErrorHandler(uc.PinAddr(AddressOf AutoVariableDefCB))
   Console.WriteLine(uc.EvalStr("1+")) ' Returns "Syntax error"
   ' Output
   ' An error has occured!
   ' Error #: 2
   ' Error Message: Syntax error
   ' Error Symbol: +
   ' Error Location: 1
   ' Error Expression: 1+

   Console.WriteLine(uc.EvalStr("5/0")) ' Returns "Division by 0"
   ' Output
   ' An error has occured!
   ' Error #: 20
   ' Error Message: Division by 0
   ' Error Symbol: 
   ' Error Location: 0
   ' Error Expression: 

   uc.Eval("AutoTest = 123")
   Console.WriteLine(uc.Eval("AutoTest * 1000")) ' Returns 123000
End Sub

          

static void ErrorHandlerTestCB(IntPtr ucPtr) {
   uCalc ucc = New uCalc(ucPtr);
   Console.WriteLine("An error has occured!");
   Console.Write("Error #: "); Console.WriteLine(ucc.ErrorNumber());
   Console.WriteLine("Error Message: " + ucc.ErrorMessage());
   Console.WriteLine("Error Symbol: " + ucc.ErrorSymbol());
   Console.WriteLine("Error Location: " + ucc.ErrorLocation());
   Console.WriteLine("Error Expression: " + ucc.ErrorExpression());
}

static void AutoVariableDefCB(IntPtr ucPtr) {
   uCalc ucc = New uCalc(ucPtr);
   if (ucc.ErrorNumber() == ErrorNumberEnum.Err_Undefined_Identifier) {
      ucc.DefineVariable(ucc.ErrorSymbol());
      ucc.ErrorResponse(ErrorHandlerResponseEnum.ErrorResume);
   }
}

static void ErrorHandler_() { // +++ example also for 2nd arg
   uc.AddErrorHandler(uc.PinAddr(ErrorHandlerTestCB));
   uc.AddErrorHandler(uc.PinAddr(AutoVariableDefCB));
   Console.WriteLine(uc.EvalStr("1+")); // Returns "Syntax error";
   // Output
   // An error has occured!
   // Error #: 2
   // Error Message: Syntax error
   // Error Symbol: +
   // Error Location: 1
   // Error Expression: 1+
   
   Console.WriteLine(uc.EvalStr("5/0")); // Returns "Division by 0";
   // Output
   // An error has occured!
   // Error #: 20
   // Error Message: Division by 0
   // Error Symbol: 
   // Error Location: 0
   // Error Expression: 
   
   uc.Eval("AutoTest = 123");
   Console.WriteLine(uc.Eval("AutoTest * 1000")); // Returns 123000;
}

          

procedure ErrorHandlerTestCB(ucPtr: System.Pointer);
begin
   
//ucc uCalc.Create(ucPtr);;
   WriteLn('An error has occured!');
   Write('Error #: ');; WriteLn(ucc.ErrorNumber());
   WriteLn('Error Message: ' + ucc.ErrorMessage());
   WriteLn('Error Symbol: ' + ucc.ErrorSymbol());
   WriteLn('Error Location: ' + ucc.ErrorLocation());
   WriteLn('Error Expression: ' + ucc.ErrorExpression());
End;

procedure AutoVariableDefCB(ucPtr: System.Pointer);
begin
   
//ucc uCalc.Create(ucPtr);;
   if ucc.ErrorNumber() = ErrorNumberEnum.Err_Undefined_Identifier Then 
begin
   
      ucc.DefineVariable(ucc.ErrorSymbol());
      ucc.ErrorResponse(ErrorHandlerResponseEnum.ErrorResume);

End;
End;

procedure ErrorHandler_();
begin
   // +++ example also for 2nd arg
   uc.AddErrorHandler(ErrorHandlerTestCB);
   uc.AddErrorHandler(AutoVariableDefCB);
   WriteLn(uc.EvalStr('1+')); // Returns 'Syntax error';
   // Output
// An error has occured!
// Error #: 2
// Error Message: Syntax error
// Error Symbol: +
// Error Location: 1
// Error Expression: 1+

   WriteLn(uc.EvalStr('5/0')); // Returns 'Division by 0';
   // Output
// An error has occured!
// Error #: 20
// Error Message: Division by 0
// Error Symbol: 
// Error Location: 0
// Error Expression: 

   uc.Eval('AutoTest = 123');
   WriteLn(uc.Eval('AutoTest * 1000')); // Returns 123000;
End;

          

void _stdcall ErrorHandlerTestCB(uCalcPtr ucPtr) {
   uCalc ucc(ucPtr);
   cout << "An error has occured!" << endl;
   cout << "Error #: "; cout << ucc.ErrorNumber() << endl;
   cout << "Error Message: " << ucc.ErrorMessage() << endl;
   cout << "Error Symbol: " << ucc.ErrorSymbol() << endl;
   cout << "Error Location: " << ucc.ErrorLocation() << endl;
   cout << "Error Expression: " << ucc.ErrorExpression() << endl;
}

void _stdcall AutoVariableDefCB(uCalcPtr ucPtr) {
   uCalc ucc(ucPtr);
   if (ucc.ErrorNumber() == ErrorNumberEnum::Err_Undefined_Identifier) {
      ucc.DefineVariable(ucc.ErrorSymbol());
      ucc.ErrorResponse(ErrorHandlerResponseEnum::ErrorResume);
   }
}

void ErrorHandler_() { // +++ example also for 2nd arg
   uc.AddErrorHandler(ErrorHandlerTestCB);
   uc.AddErrorHandler(AutoVariableDefCB);
   cout << uc.EvalStr("1+") << endl; // Returns "Syntax error";
   // Output
   // An error has occured!
   // Error #: 2
   // Error Message: Syntax error
   // Error Symbol: +
   // Error Location: 1
   // Error Expression: 1+
   
   cout << uc.EvalStr("5/0") << endl; // Returns "Division by 0";
   // Output
   // An error has occured!
   // Error #: 20
   // Error Message: Division by 0
   // Error Symbol: 
   // Error Location: 0
   // Error Expression: 
   
   uc.Eval("AutoTest = 123");
   cout << uc.Eval("AutoTest * 1000") << endl; // Returns 123000;
}

          

static void ErrorHandlerTestCB(uCalcPtr ucPtr) {
   uCalc ucc(ucPtr);
   Console::WriteLine("An error has occured!");
   Console::Write("Error #: "); Console::WriteLine(ucc.ErrorNumber());
   Console::WriteLine("Error Message: " + ucc.ErrorMessage());
   Console::WriteLine("Error Symbol: " + ucc.ErrorSymbol());
   Console::WriteLine("Error Location: " + ucc.ErrorLocation());
   Console::WriteLine("Error Expression: " + ucc.ErrorExpression());
}

static void AutoVariableDefCB(uCalcPtr ucPtr) {
   uCalc ucc(ucPtr);
   if (ucc.ErrorNumber() == ErrorNumberEnum::Err_Undefined_Identifier) {
      ucc.DefineVariable(ucc.ErrorSymbol());
      ucc.ErrorResponse(ErrorHandlerResponseEnum::ErrorResume);
   }
}

static void ErrorHandler_() { // +++ example also for 2nd arg
   uc.AddErrorHandler(ucPinAddr(ErrorHandlerTestCB));
   uc.AddErrorHandler(ucPinAddr(AutoVariableDefCB));
   Console::WriteLine(uc.EvalStr("1+")); // Returns "Syntax error";
   // Output
   // An error has occured!
   // Error #: 2
   // Error Message: Syntax error
   // Error Symbol: +
   // Error Location: 1
   // Error Expression: 1+
   
   Console::WriteLine(uc.EvalStr("5/0")); // Returns "Division by 0";
   // Output
   // An error has occured!
   // Error #: 20
   // Error Message: Division by 0
   // Error Symbol: 
   // Error Location: 0
   // Error Expression: 
   
   uc.Eval("AutoTest = 123");
   Console::WriteLine(uc.Eval("AutoTest * 1000")); // Returns 123000;
}

          
DLL import code
<DllImport(uCalcDLL, CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Cdecl, EntryPoint:="ErrorResponse")> _

Private Sub ErrorResponse__(ByVal uCalcHandle As IntPtr,ByVal Response As ErrorHandlerResponseEnum)
End Sub
            
[DllImport(uCalcDLL, CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl, EntryPoint="ErrorResponse")]

protected static extern  void ErrorResponse_(IntPtr uCalcHandle,ErrorHandlerResponseEnum Response);
            
{DLLImport}procedure ErrorResponse__(uCalcHandle: System.Pointer;Response: ErrorHandlerResponseEnum); cdecl; external uCalcDLL name 'ErrorResponse';

            
typedef  void (* __ErrorResponse)(void *uCalcHandle, ErrorHandlerResponseEnum Response); 

            
[DllImport(uCalcLib, CharSet=CharSet::Ansi, CallingConvention=CallingConvention::Cdecl, EntryPoint = "ErrorResponse")]

static void ErrorResponse_(void *  uCalcHandle, ErrorHandlerResponseEnum Response);
            
See also
Prev | Next