Microsoft.Silverlight.Testing.Harness.GlobalExceptionHandler.GetExceptionObject C# (CSharp) Метод

GetExceptionObject() публичный статический Метод

Return the Exception property from the EventArgs.
This method is compatible with the full desktop framework as well as Silverlight.
public static GetExceptionObject ( EventArgs e ) : Exception
e System.EventArgs Event arguments.
Результат System.Exception
        public static Exception GetExceptionObject(EventArgs e)
        {
            #if SILVERLIGHT
            ApplicationUnhandledExceptionEventArgs args = e as ApplicationUnhandledExceptionEventArgs;
            #else
            UnhandledExceptionEventArgs args = e as UnhandledExceptionEventArgs;
            #endif
            return (args != null) ? args.ExceptionObject : null;
        }

Usage Example

 /// <summary>
 /// Listener event for any unhandled exceptions.
 /// </summary>
 /// <param name="sender">Sender object instance.</param>
 /// <param name="e">Event arguments.</param>
 private void GlobalUnhandledExceptionListener(object sender, EventArgs e)
 {
     if (DispatcherStack.CurrentCompositeWorkItem is CompositeWorkItem)
     {
         CompositeWorkItem cd        = (CompositeWorkItem)DispatcherStack.CurrentCompositeWorkItem;
         Exception         exception = GlobalExceptionHandler.GetExceptionObject(e);
         cd.WorkItemException(exception);
         GlobalExceptionHandler.ChangeExceptionBubbling(e, /* handled */ true);
     }
     else
     {
         GlobalExceptionHandler.ChangeExceptionBubbling(e, /* handled */ false);
     }
 }