Back to Devexpress

SpreadsheetControl.UnhandledException Event

wpf-devexpress-dot-xpf-dot-spreadsheet-dot-spreadsheetcontrol-192517a3.md

latest5.3 KB
Original Source

SpreadsheetControl.UnhandledException Event

This event is raised when an exception unhandled by the SpreadsheetControl occurs.

Namespace : DevExpress.Xpf.Spreadsheet

Assembly : DevExpress.Xpf.Spreadsheet.v25.2.dll

NuGet Package : DevExpress.Wpf.Spreadsheet

Declaration

csharp
public event UnhandledExceptionEventHandler UnhandledException
vb
Public Event UnhandledException As UnhandledExceptionEventHandler

Event Data

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

PropertyDescription
ExceptionGets the exception which triggers the UnhandledException event.
HandledGets or sets whether the exception should be propagated upwards.

Remarks

The UnhandledException event is helpful when a command is executed via the Bar (Ribbon) user interface, and you are unable to catch the exception which is likely to occur. The most common case is an attempt to save the document to a read-only or locked file. If you do not handle the UnhandledException event, the unhandled exception is thrown and the application crashes. All changes in the document are lost. To prevent this, handle the exception using the following code.

csharp
private void spreadsheetControl1_UnhandledException(object sender, 
    DevExpress.XtraSpreadsheet.SpreadsheetUnhandledExceptionEventArgs e)
{
    e.Handled = true;
    // Add your code to handle the exception.
    BeginInvoke(new MethodInvoker(delegate()
    {
        MessageBox.Show(e.Exception.Message, "The command is not completed!");
    }));
}
vb
Private Shared My_Exception As Exception

Private Sub spreadsheetControl1_UnhandledException(ByVal sender As Object, _
        ByVal e As DevExpress.XtraSpreadsheet.SpreadsheetUnhandledExceptionEventArgs) _
        Handles spreadsheetControl1.UnhandledException
    My_Exception = e.Exception
    e.Handled = True
    ' Add your code to handle the exception.
    BeginInvoke(New MethodInvoker(AddressOf ShowMessageMethod))
End Sub
Private Shared Sub ShowMessageMethod()
    MessageBox.Show(My_Exception.Message, "The command is not completed!")
End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the UnhandledException event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-spreadsheet-create-custom-progress-indicator/CS/WpfSpreadsheetProgressSample/MainWindow.xaml#L20

xml
ShowStatusBar="True"
                              UnhandledException="spreadsheetControl1_UnhandledException"/>
</Grid>

wpf-spreadsheet-create-custom-progress-indicator/CS/WpfSpreadsheetProgressSample/obj/Debug/net8.0-windows/MainWindow.g.cs#L97

csharp
#line 20 "..\..\..\MainWindow.xaml"
this.spreadsheetControl1.UnhandledException += new DevExpress.XtraSpreadsheet.UnhandledExceptionEventHandler(this.spreadsheetControl1_UnhandledException);

wpf-spreadsheet-create-custom-progress-indicator/VB/WpfSpreadsheetProgressSample/obj/Debug/net8.0-windows/MainWindow.g.vb#L97

vb
#ExternalSource("..\..\..\MainWindow.xaml",20)
AddHandler Me.spreadsheetControl1.UnhandledException, New DevExpress.XtraSpreadsheet.UnhandledExceptionEventHandler(AddressOf Me.spreadsheetControl1_UnhandledException)

See Also

SpreadsheetControl Class

SpreadsheetControl Members

DevExpress.Xpf.Spreadsheet Namespace