Back to Devexpress

JsonDataSourceException Class

corelibraries-devexpress-dot-dataaccess-dot-json-07478fc2.md

latest3.6 KB
Original Source

JsonDataSourceException Class

An exception that occurs when an attempt to fill a JsonDataSource with data fails.

Namespace : DevExpress.DataAccess.Json

Assembly : DevExpress.DataAccess.v25.2.dll

NuGet Package : DevExpress.DataAccess

Declaration

csharp
public class JsonDataSourceException :
    Exception
vb
Public Class JsonDataSourceException
    Inherits Exception

Remarks

The JsonDataSourceException is thrown when a call to the Fill() method fails to populate the data source with data and supercedes 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.

Enclose the JsonDataSource.Fill method call in the try block and catch JsonDataSourceException :

csharp
try {
  dataSource.Fill()
}
catch(JsonDataSourceException) {
  //do something
}
vb
Try
  dataSource.Fill()
Catch e1 As JsonDataSourceException
  'do something
End Try

As an alternative to catching JsonDataSourceException , you can handle the JsonDataSource.FillError event to process WebException , IOException , and JSON data parse errors.

Example

The code sample below creates a new data source, calls the Fill method to populate the data source with data, and catches the JsonDataSourceException exception that may occur during the Fill method call.

csharp
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
};
try {
    datasource.Fill();
}
catch (JsonDataSourceException) {
    // Add code to process JsonDataSourceException here.
}
vb
Imports DevExpress.DataAccess
Imports DevExpress.DataAccess.Json
' ...
' Create a new JSON source.
Dim jsonSource = New UriJsonSource() With {.Uri = New Uri("https://invalid.json")}
' Assign the JSON source to the data source.
Dim datasource = New JsonDataSource() With {.JsonSource = jsonSource}
Try
    datasource.Fill()
Catch e1 As JsonDataSourceException
    ' Add code to process JsonDataSourceException here.
End Try

Inheritance

Object Exception JsonDataSourceException

See Also

JsonDataSourceException Members

DevExpress.DataAccess.Json Namespace