Error
Handling
See Also: Exception Handling, ucError, ucSetError, ucErrorMessage
Error handling callback routines
uCalc FMP allows you to create error handling callback routines, which handle errors/exceptions wherever they my occur, whether during the parsing stage, or during the evaluation stage. With a centralized error handler, it is not necessary to individually check for errors after each uCalc definition or evaluation. Your error handling callback routine(s) will be invoked the moment an error occurs.
Example:
' This example displays an error message box when an
error occurs
Function MyErrorHandler(ByVal t As Long) As Long
MsgBox
ucErrorMessage(0, t)
End Function
Dim eHandler As Long
eHandler = uCalc(uc_AddErrorHandler, 0, AddressOf MyErrorHandler)
ucErrorMessage([ErrorNumber [, ThreadHandle]])
This function retrieves the text associated with an error number. If the ErrorNumber argument is omitted, or equal to 0, then the current error message is returned. When you invoke ucErrorMessage from a callback routine, you should always include the second argument. This argument is the one value that is passed as an argument to your callback routine. See ucErrorMessage.
Pre-defined constants for ErrorNumber are:
uc_Err_None
uc_Err_Syntax_Error
uc_Err_Undefined_Identifier
uc_Err_Unknown_Error
uc_Err_Unrecognized_Pattern
uc_Err_Unrecognized_Command
uc_Err_Datatype_Mismatch
uc_Err_Invalid_Argument_Count
uc_Err_Invalid_Definition
uc_Err_CodeBlock_Error
uc_Err_Undefined_Callback
uc_Err_Array_Bounds_Exceeded
uc_Err_Float_Denormal_Operand
uc_Err_Float_Divide_By_Zero
uc_Err_Float_Inexact_Result
uc_Err_Float_Invalid_Operation
uc_Err_Float_Overflow
uc_Err_Float_Stack_Check
uc_Err_Float_Underflow
uc_Err_Integer_Divide_By_Zero
uc_Err_Integer_Overflow
uc_Err_Privileged_Instruction
ucError
This routine is basically a left-over from version 2.0 of uCalc, where you might check the value of ucError after every call to routines such as ucParse, ucEval, or ucEvaluate, etc... If you use an error handling routine, you will typically not need ucError. See ucError.
ucGetSymbol
If there is a symbol name associated with an error, such as a name in an expression that is not recognized as a defined function or variable, then your callback can retrieve this name with ucGetSymbol. This function takes one argument, which represents the handle of the given thread as passed to the error handling callback routine.
Raising an error
You can raise an error using ucSetError(ErrorNumber [, ThreadHandle]) . See ucSetError.
Clearing an error
Generally, the error value is cleared prior to each new uCalc transaction. The exception to this is ucEvaluate. The error value is not cleared when you call ucEvaluate. To clear an error, use uCalc(uc_ErrorClear).