1. Description
The component provide a complete and fine-grained management of errors when an expression is parsed and executed/evaluated. Several error code , more than 50, are available to describe with precision the error.
There are two main kinds of error:
- Expression Error
- Parse Error
- Execution/evaluation Error
- Licence Error
- Configuration Error (var definition and function attachment).
2. Manage expression error
This case concerns errors occuring when a expression is wrong, during the parse stage or during the execution/evaluation stage.
The standard and easiest way to manage these sort of errors is to check it after the execution/evaluation of an expression.
Example, the code below try to compare an integer and a boolean, an error occurs:
ExpressionEval evaluator = new ExpressionEval();
// 1-parse the expression, find variables
evaluator.Parse("a=b");
// 2-set variables values
evaluator.DefineVarInt("a", 4);
evaluator.DefineVarInt("b", 5);
// 3-evaluate expression
ExecResult execResult = evaluator.Exec();
// 4-check the result
if (execResult.HasError)
{
// display the error code
Console.WriteLine("The expr '" + expr + "' has errors, nb=" + execResult.ListError.Count);
ExprError error = execResult.ListError[0];
Console.WriteLine("Error code: " + error.Code);
// display the error parameter (the position of the wrong token)
Console.WriteLine("Error param: " + error.ListErrorParam[0].Key+ "= " + error.ListErrorParam[0].Value);
return;
}
The error code returned is: ExprComparisonOperandsTypeMismatchIntExpected.
The console should displays :
====The expression is: (a=b) The expr '(a=b)' has errors, nb=1 Error code: ExprComparisonOperandsTypeMismatchIntExpected Error param: Position= 3
Another way is to check error just after the parse stage and then again after the execution/evaluation stage.
3. Manage license error
Concerning the license of the component, several errors can occurs:
- ErrorBadFormed
- The string license key is wrong.
- ErrorDataWrong
- One or more license property is wrong (can be a date or an expected value).
- ErrorOutOfDate
- The license is out of date (too old).
- ErrorLicenceProductDoesntMatchComponentProduct
- The license does not concern the component.
Here is an example of an out of date license set to the component:
ExpressionEval evaluator = new ExpressionEval();
// the generated encrypted licence info
string encryptedLicence = "P2OAd87qJOBDKit09Z5EM89kul1WmlGNXAkTseJdV8le+h9bmZHB6MC5fisGqFXoqmRlqvYxJeF3bDHhmm/4cMV11/xqqgWeGcBLnozWyEoxsbJRaWdTOkxldifspwEyyhYeLw75zgc=";
LicenseInfoStatus res = evaluator.License.SetLicenseInfo(encryptedLicence);
Console.WriteLine("LicenseInfoStatus (should be ErrorOutOfDate): " + res.ToString());
// is the current licence valid?
bool isLicenceValid = evaluator.License.IsValid();
Console.WriteLine("Is licence valid (should be false)? " + isLicenceValid.ToString());
// parse an expression, should finish with success
ParseResult parseResult = evaluator.Parse("a=b");
// should finish with ERROR
Console.WriteLine("error occurs (due to a license problem) (should be true)? " + parseResult.HasError);
Console.WriteLine("error code (should be LicenceInvalid): " + parseResult.ListError[0].Code.ToString());
The console should displays :
====Set an Out of date license: LicenseInfoStatus (should be ErrorOutOfDate): ErrorOutOfDate Is licence valid (should be false)? False error occurs (due to a license problem) (should be true)? True error code (should be LicenceInvalid): LicenceInvalid