How to control the way the grid handles the exceptions in WinForms GridControl?
Grid handle the exception
There is a class called Syncfusion.Windows.Forms.ExceptionManager having static members that you can use to control the way the Grid handles exceptions. You can temporarily suspend and resume catching exceptions by using the SuspendCatchExceptions() and ResumeCatchExceptions() methods.
The ExceptionManager class has the following methods to control the exceptions:
C#
//Suspends catching exceptions. Syncfusion.Windows.Forms.ExceptionManager.SuspendCatchExceptions(); //Resumes catching exceptions. ExceptionManager.ResumeCatchExceptions();
VB
'Suspends catching exceptions. Syncfusion.Windows.Forms.ExceptionManager.SuspendCatchExceptions() 'Resumes catching exceptions. ExceptionManager.ResumeCatchExceptions()
- ExceptionCatched Event:
Hook the Syncfusion.Windows.Forms.ExceptionManager.ExceptionCatched event to catch any exception and handle it within the event or throw it again.
C#
ExceptionManager.ExceptionCatched += ExceptionManager_ExceptionCatched; //ExceptionManager.RaiseExceptionCatched() method firex this event. void ExceptionManager_ExceptionCatched(object sender, ExceptionCatchedEventArgs e) { // Exception Handling is done here. }
VB
Private ExceptionManager.ExceptionCatched += AddressOf ExceptionManager_ExceptionCatched 'ExceptionManager.RaiseExceptionCatched() method fires this event. Private Sub ExceptionManager_ExceptionCatched(ByVal sender As Object, ByVal e As ExceptionCatchedEventArgs) 'Exception Handling is done here. End Sub
Hook the event before the InitializeComponent() method to catch the exceptions globally.
- RaiseExceptionCatched()
The ExceptionManager.RaiseExceptionCatched method raises the ExceptionCatched event and notifies the ExceptionManager about the exceptions caught.
C#
ExceptionManager.RaiseExceptionCatched(this, exception)
VB
ExceptionManager.RaiseExceptionCatched(Me, exception)
- PassThroughExceptions:
You also have the option to disable catching exceptions altogether by setting the PassThroughExceptions value to true.
C#
ExceptionManager.PassThroughExceptions = true;
VB
ExceptionManager.PassThroughExceptions = true;
Samples: