Back to Devexpress

AppointmentExchanger.OnException Event

corelibraries-devexpress-dot-xtrascheduler-dot-exchange-dot-appointmentexchanger-80a4a789.md

latest5.3 KB
Original Source

AppointmentExchanger.OnException Event

Occurs if an exception is raised during the export/import process.

Namespace : DevExpress.XtraScheduler.Exchange

Assembly : DevExpress.XtraScheduler.v25.2.Core.dll

NuGet Package : DevExpress.Scheduler.Core

Declaration

csharp
public event ExchangeExceptionEventHandler OnException
vb
Public Event OnException As ExchangeExceptionEventHandler

Event Data

The OnException event's data class is ExchangeExceptionEventArgs. The following properties provide information specific to this event:

PropertyDescription
HandledGets or sets whether an event was handled. If it was handled, the exception is not propagated.
OriginalExceptionProvides access to a .NET exception which originated this event.

Remarks

Handle this event to intercept exceptions thrown during export/import processes started by AppointmentExporter.Export or AppointmentImporter.Import methods. When necessary, you can terminate the process by calling the AppointmentExchanger.Terminate method.

The following code illustrates handling exceptions that may occur during an import operation performed by the iCalendarImporter.

To handle exceptions, subscribe to the AppointmentExchanger.OnException event before calling the AppointmentImporter.Import method. When an exception occurs, the import process is terminated, so no data are loaded into the Scheduler.

If an exception fires while parsing iCal data, a cast of event arguments object to the iCalendarParseExceptionEventArgs type is performed successfully and the information on the iCalendarParseExceptionEventArgs.LineIndex and the iCalendarParseExceptionEventArgs.LineText is displayed. Otherwise Exception object is retrieved, to display the exception description.

csharp
using DevExpress.XtraScheduler;
using DevExpress.XtraScheduler.iCalendar;
        void importer_OnException(object sender, ExchangeExceptionEventArgs e) {
            iCalendarParseExceptionEventArgs args = e as iCalendarParseExceptionEventArgs;
            if (args != null) {
                if (ckhBreakOnError.Checked) {
                    iCalendarImporter importer = (iCalendarImporter)sender;
                    importer.Terminate();
                }
                ShowErrorMessage(String.Format("Cannot parse line {0} with text '{1}'",
                    args.LineIndex, args.LineText));
            }
            else
                ShowErrorMessage(e.OriginalException.Message);

            e.Handled = true; // prevent this exception from throwing
        }
vb
Imports DevExpress.XtraScheduler
Imports DevExpress.XtraScheduler.iCalendar
        Private Sub importer_OnException(ByVal sender As Object, ByVal e As ExchangeExceptionEventArgs)
            Dim args As iCalendarParseExceptionEventArgs = TryCast(e, iCalendarParseExceptionEventArgs)
            If args IsNot Nothing Then
                If ckhBreakOnError.Checked Then
                    Dim importer As iCalendarImporter = DirectCast(sender, iCalendarImporter)
                    importer.Terminate()
                End If
                ShowErrorMessage(String.Format("Cannot parse line {0} with text '{1}'", args.LineIndex, args.LineText))
            Else
                ShowErrorMessage(e.OriginalException.Message)
            End If

            e.Handled = True ' prevent this exception from throwing
        End Sub

See Also

Terminate()

IsTermination

AppointmentExchanger Class

AppointmentExchanger Members

DevExpress.XtraScheduler.Exchange Namespace