Articles in this section
Category / Section

How to control the way the grid handles the exceptions in WinForms GridControl?

1 min read

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()
  1. 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

 

Note:

Hook the event before the InitializeComponent() method to catch the exceptions globally.

 

  1. 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)
  1. 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:

VB: ExceptionHandling-VB-881505255.zip

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied