# Error Reporting

## Content

[ExpressionEditor](/componentone/api/win/online-expressioneditor/dotnet-api/C1.Win.ExpressionEditor.10/C1.Win.ExpressionEditor.html) validates expressions after input is completed. If an expression contains invalid syntax or unsupported tokens, the control detects the error and displays a validation message within the editor.
This validation behavior helps identify and correct errors before expression evaluation or execution.

***

## Error Display and Validation

Error reporting in `ExpressionEditor` provides immediate feedback for invalid expressions. The control supports:

* error display through the [ShowErrorBox](/componentone/api/win/online-expressioneditor/dotnet-api/C1.Win.ExpressionEditor.10/C1.Win.ExpressionEditor.C1ExpressionEditor.ShowErrorBox.html) property
* syntax highlighting through the [UnderlineErrors](/componentone/api/win/online-expressioneditor/dotnet-api/C1.Win.ExpressionEditor.10/C1.Win.ExpressionEditor.C1ExpressionEditor.UnderlineErrors.html) property
* validation checks through the [IsValid](/componentone/api/win/online-expressioneditor/dotnet-api/C1.Win.ExpressionEditor.10/C1.Win.ExpressionEditor.C1ExpressionEditor.IsValid.html) property.

These features help identify, display, and correct expression errors during editing.
`ExpressionEditor` provides visual options for displaying validation errors within the user interface.

***

### ShowErrorBox

The [ShowErrorBox](/componentone/api/win/online-expressioneditor/dotnet-api/C1.Win.ExpressionEditor.10/C1.Win.ExpressionEditor.C1ExpressionEditor.ShowErrorBox.html) property controls whether an error message is displayed within the editor when a syntax error occurs.
**Declaration**

```auto
public bool ShowErrorBox { get; set; }
```

```auto
c1ExpressionEditor1.ShowErrorBox = true;
```

| Property | Description |
| -------- | ----------- |
| ShowErrorBox | Displays error messages for invalid expressions. |

***

### UnderlineErrors

The [UnderlineErrors](/componentone/api/win/online-expressioneditor/dotnet-api/C1.Win.ExpressionEditor.10/C1.Win.ExpressionEditor.C1ExpressionEditor.UnderlineErrors.html) property controls whether invalid portions of an expression are visually underlined.

>type=note
> <span data-loadable-vc-wrapper="true" data-ssr-placeholder-replace="Hm6N8:EfLS5:z8NN7:qz-Pe:OP-5u-0">Note: Note: The feature requires </span>**<span data-loadable-vc-wrapper="true" data-ssr-placeholder-replace="Hm6N8:EfLS5:z8NN7:qz-Pe:OP-5u-0">IntelliSyntaxHighlightingEnabled</span>**<span data-loadable-vc-wrapper="true" data-ssr-placeholder-replace="Hm6N8:EfLS5:z8NN7:qz-Pe:OP-5u-0"> to be enabled.</span>

**Declaration**

```auto
public bool UnderlineErrors { get; set; }
```

```auto
c1ExpressionEditor1.UnderlineErrors = true;
```

| Property | Description |
| -------- | ----------- |
| UnderlineErrors | Controls whether invalid portions of an expression are visually underlined. |

***

### Validation

The [IsValid](/componentone/api/win/online-expressioneditor/dotnet-api/C1.Win.ExpressionEditor.10/C1.Win.ExpressionEditor.C1ExpressionEditor.IsValid.html) property indicates whether an expression passes validation.

* `true` → The expression is valid and can be evaluated.
* `false` → The expression contains validation errors and cannot be evaluated.

**Example**

```auto
if (c1ExpressionEditor1.IsValid)
{
    // Expression is valid
}
```

***

## GetErrors Method

The [GetErrors()](/componentone/api/win/online-expressioneditor/dotnet-api/C1.Win.ExpressionEditor.10/C1.Win.ExpressionEditor.C1ExpressionEditor.GetErrors.html) method retrieves the validation errors detected in the current expression. The method returns a collection of [ErrorInfo](/componentone/api/win/online-expressioneditor/dotnet-api/C1.Win.ExpressionEditor.10/C1.ExpressionEditor.Engine.ErrorInfo.html) objects that describe syntax or validation issues identified by the editor.

```auto
List<ErrorInfo> errors = c1ExpressionEditor1.GetErrors();
```

**Declaration**

```auto
public List<ErrorInfo> GetErrors()
```

**Return Type**

| Type | Description |
| ---- | ----------- |
| List\<ErrorInfo> | A collection of `ErrorInfo` objects that contain expression error details. |

***

## ItemContext Property

The [ItemContext](/componentone/api/win/online-expressioneditor/dotnet-api/C1.Win.ExpressionEditor.10/C1.Win.ExpressionEditor.C1ExpressionEditor.ItemContext.html) property specifies the data object used as the evaluation context for expressions.
`ItemContext` represents the active data item used during expression evaluation. When the [DataSource](/componentone/api/win/online-expressioneditor/dotnet-api/C1.Win.ExpressionEditor.10/C1.Win.ExpressionEditor.C1ExpressionEditor.DataSource.html) property is assigned, the control typically configures `ItemContext` automatically. Manual assignment is required only when custom evaluation behavior is needed.
**Declaration**

```auto
public object ItemContext { get; set; }
```

**Example**

```auto
c1ExpressionEditor1.ItemContext = currentRow;
```

***

## Result Preview

`ExpressionEditor` provides a result preview feature that evaluates and displays the output of an expression before it is applied.
This behavior helps verify expression accuracy and preview evaluation results within the current data context. Evaluation errors are displayed when the expression cannot be processed.
**Evaluation Behavior**

* Expressions are evaluated only when validation succeeds.
* Evaluation uses the current data context.
* Successful evaluation returns the computed result.
* Failed evaluation returns `false`, and error information is available for retrieval.

***

### TryEvaluate Method

The [TryEvaluate](/componentone/api/win/online-expressioneditor/dotnet-api/C1.Win.ExpressionEditor.10/C1.Win.ExpressionEditor.C1ExpressionEditor.TryEvaluate.html) method evaluates the current expression and returns a Boolean value indicating whether evaluation completed successfully. When evaluation succeeds, the result is returned through the `out` parameter.
The following example evaluates an expression and assigns the result to a text box when evaluation succeeds:
**Declaration**

```auto
public bool TryEvaluate(out object result)
```

```auto
object result;

if (c1ExpressionEditor1.TryEvaluate(out result))
{
    textBox1.Text = result.ToString();
}
```

**Parameters**

| Parameter | Type | Description |
| --------- | ---- | ----------- |
| result | object | The `result` parameter contains the evaluated expression value when evaluation succeeds. |

***

## Example with Data Binding

In data-bound scenarios, expressions are evaluated against the current item in the bound data source.
The following example assigns the current `DataRow` to [ItemContext](/componentone/api/win/online-expressioneditor/dotnet-api/C1.Win.ExpressionEditor.10/C1.Win.ExpressionEditor.C1ExpressionEditor.ItemContext.html), evaluates the expression, and displays either the result or validation errors:

```auto
var table = _data.DataSource as DataTable;
c1ExpressionEditor1.ItemContext = table.Rows[_data.Position];

object result;
if (c1ExpressionEditor1.TryEvaluate(out result))
{
    textBox1.Text = result.ToString();
}
else
{
    textBox1.Text = c1ExpressionEditor1.GetErrors()[0].ToString();
}
```

**Expression Evaluation Sequence**
Expression evaluation follows a validation and execution sequence that includes validation, context assignment, evaluation, and error handling:

1. `IsValid` validates the expression before evaluation.
2. `ItemContext` assigns the current data item used during evaluation.
3. `TryEvaluate` evaluates the expression against the current context.
4. Successful evaluation returns the evaluated result for display or processing.
5. Failed evaluation returns validation details through `GetErrors()`.