Class ExceptionManager
Provides a global hook for exceptions that have been cached inside the framework and gives you the option to provide specialized handling of the exception. You can also temporarily suspend and resume caching exceptions.
Inheritance
Namespace: Syncfusion.Windows.GridCommon
Assembly: Syncfusion.GridCommon.WPF.dll
Syntax
public class ExceptionManager : Object
Remarks
The Syncfusion framework notifies ExceptionManager about exceptions that are cached by calling RaiseExceptionCatched(Object, Exception) or ExceptionManager.
The RaiseExceptionCatched(Object, Exception) method will raise the ExceptionCatched event. By handling the ExceptionCatched event, your code can analyze the exception that was cached and optionally let it bubble up by rethrowing the exception.
Your code can also temporarily suspend and resume caching exceptions. This is useful if you want to provide your own exception handling. Just call SuspendCatchExceptions() to disable handling exceptions and ResumeCatchExceptions() to resume caching exceptions.
You also have the options to disable caching exceptions altogether by setting PassThroughExceptions to True.
Note: All static settings for this class are thread local.
Examples
// The following example demonstrates temporarily suspending exception caching when calling a base class version
// of a method.
protected override void OnMouseDown(MouseEventArgs e)
{
ExceptionManager.SuspendCatchExceptions();
try
{
base.OnMouseDown(e);
ExceptionManager.ResumeCatchExceptions();
}
catch (Exception ex)
{
ExceptionManager.ResumeCatchExceptions();
// Notify exception manager about the catched exception and
// give it a chance to optionally rethrow the exception if necessary
// (e.g. if this OnMouseDown was called from another class that
// wants to provide its own exception handling).
if (!ExceptionManager.RaiseExceptionCatched(this, ex))
throw ex;
// handle exception here
MessageBox.Show(ex.ToString());
}
}
// This code sample shows how exceptions are handled within the framework:
try
{
CurrentCell.Refresh();
}
catch (Exception ex)
{
TraceUtil.TraceExceptionCatched(ex);
if (!ExceptionManager.RaiseExceptionCatched(this, ex))
throw ex;
}
Constructors
ExceptionManager()
Declaration
public ExceptionManager()
Properties
PassThroughExceptions
Lets you disable caching exceptions altogether by setting PassThroughExceptions to True.
Declaration
public static bool PassThroughExceptions { get; set; }
Property Value
Type |
---|
System.Boolean |
Methods
add_ExceptionCatched(ExceptionCatchedEventHandler)
Declaration
public static void add_ExceptionCatched(ExceptionCatchedEventHandler value)
Parameters
Type | Name | Description |
---|---|---|
ExceptionCatchedEventHandler | value |
RaiseExceptionCatched(Object, ExceptionCatchedEventArgs)
Raises the ExceptionCatched event. If caching exceptions has been disabled by a SuspendCatchExceptions() call or if PassThroughExceptions has been set to True, the exception is rethrown.
Declaration
public static bool RaiseExceptionCatched(object sender, ExceptionCatchedEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.Object | sender | |
ExceptionCatchedEventArgs | e | A ExceptionCatchedEventArgs that contains the event data. |
Returns
Type |
---|
System.Boolean |
RaiseExceptionCatched(Object, Exception)
Raises the ExceptionCatched event. If caching exceptions has been disabled by a SuspendCatchExceptions() call or if PassThroughExceptions has been set to True, the exception is rethrown.
Declaration
public static bool RaiseExceptionCatched(object sender, Exception ex)
Parameters
Type | Name | Description |
---|---|---|
System.Object | sender | |
System.Exception | ex | A System.Exception that was cached. |
Returns
Type |
---|
System.Boolean |
remove_ExceptionCatched(ExceptionCatchedEventHandler)
Declaration
public static void remove_ExceptionCatched(ExceptionCatchedEventHandler value)
Parameters
Type | Name | Description |
---|---|---|
ExceptionCatchedEventHandler | value |
ResumeCatchExceptions()
Temporariliy resumes caching exceptions.
Declaration
public static void ResumeCatchExceptions()
ShouldCatchExceptions()
Indicates whether exceptions should be cached or if they should bubble up. RaiseExceptionCatched(Object, ExceptionCatchedEventArgs) calls this method.
Declaration
public static bool ShouldCatchExceptions()
Returns
Type |
---|
System.Boolean |
SuspendCatchExceptions()
Temporariliy suspends caching exceptions.
Declaration
public static void SuspendCatchExceptions()
Events
ExceptionCatched
Occurs when an exception was cached within the framework and ExceptionManager was notified.
Declaration
public static event ExceptionCatchedEventHandler ExceptionCatched
Event Type
Type |
---|
ExceptionCatchedEventHandler |