JsonDataSource.FillError Event
Occurs when an attempt to fill the data source fails.
Namespace: DevExpress.DataAccess.Json
Assembly: DevExpress.DataAccess.v24.2.dll
NuGet Package: DevExpress.DataAccess
#Declaration
public event DataSourceFillErrorEventHandler FillError
#Event Data
The FillError event's data class is DataSourceFillErrorEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Connection |
Specifies the name of the JSON data source connection that was used when the Fill |
Exception |
Gets the exception that caused the Fill |
Handled |
Gets or sets whether the Fill |
#Remarks
This event occurs when a call to the Fill() method fails to populate the data source with data. Handle this event to process the following exceptions:
- WebExceptions that occur when the endpoint’s Uri is not accessible.
- IOExceptions that occur on failed attempts to load JSON data from the file system.
- JSON data parse errors.
Use the following properties to retrieve the exception details:
- DataSourceFillErrorEventArgs.ConnectionName - the name of the connection that was used when the FillError event occurred.
- DataSourceFillErrorEventArgs.Exception - the data source exception that was thrown. This is a WebException, IOException, or a parse exception.
- DataSourceFillErrorEventArgs.Handled - specifies if the exception is handled.
The JsonDataSourceException exception occurs instead of the WebException, IOException, and parse errors. Catch this exception as an alternative to the FillError event.
#Example
The code sample below creates a new data source, handles the FillError event to to process exceptions, and tries to populate the data source with data.
using DevExpress.DataAccess;
using DevExpress.DataAccess.Json;
// ...
// Create a new JSON source.
var jsonSource = new UriJsonSource() {
Uri = new Uri(@"https://invalid.json")
};
// Assign the JSON source to the data source.
var datasource = new JsonDataSource() {
JsonSource = jsonSource
};
datasource.FillError += (s, e) => {
e.Handled = true;
// Add code that handles the data source fill error here.
};