-
Notifications
You must be signed in to change notification settings - Fork 0
Error handling
amomra edited this page Apr 22, 2015
·
1 revision
In case of an error the libraryL provide similar methods for querying the information associated with the error. This information will be in the properties of a ParserError exception object thrown by the parser.
These properties are:
-
exception.Message- returns the error message. -
exception.Expr- returns the current formula (if a formula is set) -
exception.Token- returns the token associated with the error (if applicable) -
exception.Pos- returns the current formula position (if applicable) -
exception.Code- returns the error code.
The following table lists the parser error codes. The first column contains the enumeration values as defined in the enumeration ErrorCodes. The second column lists their numeric code and the third column contains the error description.
| Enumeration name | Value | Description |
|---|---|---|
UNEXPECTED_OPERATOR |
0 | Unexpected binary operator found |
UNASSIGNABLE_TOKEN |
1 | Token cant be identified |
UNEXPECTED_EOF |
2 | Unexpected end of formula. (Example: "2+sin(") |
UNEXPECTED_ARG_SEP |
3 | An unexpected argument separator has been found. (Example: "1,23") |
UNEXPECTED_ARG |
4 | An unexpected argument has been found |
UNEXPECTED_VAL |
5 | An unexpected value token has been found |
UNEXPECTED_VAR |
6 | An unexpected variable token has been found |
UNEXPECTED_PARENS |
7 | Unexpected parenthesis, opening or closing |
UNEXPECTED_STR |
8 | A string has been found at an inapropriate position |
STRING_EXPECTED |
9 | A string function has been called with a different type of argument |
VAL_EXPECTED |
10 | A numerical function has been called with a non value type of argument |
MISSING_PARENS |
11 | Missing parens. (Example: "3*sin(3") |
UNEXPECTED_FUN |
12 | Unexpected function found. (Example: "sin(8)cos(9)") |
UNTERMINATED_STRING |
13 | unterminated string constant. (Example: "3*valueof("hello)") |
TOO_MANY_PARAMS |
14 | Too many function parameters |
TOO_FEW_PARAMS |
15 | Too few function parameters. (Example: "ite(1<2,2)") |
OPRT_TYPE_CONFLICT |
16 | binary operators may only be applied to value items of the same type |
STR_RESULT |
17 | result is a string |
INVALID_NAME |
18 | Invalid function, variable or constant name. |
INVALID_BINOP_IDENT |
19 | Invalid binary operator identifier. |
INVALID_INFIX_IDENT |
20 | Invalid infix operator identifier. |
INVALID_POSTFIX_IDENT |
21 | Invalid postfix operator identifier. |
BUILTIN_OVERLOAD |
22 | Trying to overload builtin operator |
INVALID_FUN_PTR |
23 | Invalid callback function pointer |
INVALID_VAR_PTR |
24 | Invalid variable pointer |
EMPTY_EXPRESSION |
25 | The expression string is empty |
NAME_CONFLICT |
26 | Name conflict |
OPT_PRI |
27 | Invalid operator priority |
DOMAIN_ERROR |
28 | catch division by zero, sqrt(-1), log(0) (currently unused) |
DIV_BY_ZERO |
29 | Division by zero (currently unused) |
GENERIC |
30 | Error that does not fit any other code but is not an internal error |
LOCALE |
31 | Conflict with current locale |
UNEXPECTED_CONDITIONAL |
32 | Unexpected if then else operator |
MISSING_ELSE_CLAUSE |
33 | Missing else clause |
MISPLACED_COLON |
34 | Misplaced colon |
INTERNAL_ERROR |
35 | Internal error of any kind. |
In case of an error the parser raises an exception of type ParserError. This class provides you with several member functions that allow querying the exact cause as well as additional information for the error.
try
{
...
parser.Eval();
...
}
catch(ParserError e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.Expr);
Console.WriteLine(e.Pos);
Console.WriteLine(e.Token);
Console.WriteLine(e.Code);
}- Getting started
- Setting and evaluating an expression
- Setting the expression
- Single return expression evaluation
- Multiple return expression evaluation
- Bulk mode evaluations
- Error handling
- Defining identifier charsets
- Defining parser variables
- Explicitely defining variables
- Implicit creation of new variables
- Querying parser variables
- Removing variables
- Defining constants
- Defining parser constants
- Querying parser constants
- Removing constants
- Setting custom value recognition callbacks
- Defining functions
- Defining parser functions
- Bulk mode functions
- Defining parser operators
- Unary operators
- Binary operators
- Disable built-in operators
- Localization