System.AggregateException.Handle C# (CSharp) Method

Handle() public method

public Handle ( bool>.Func predicate ) : void
predicate bool>.Func
return void
        public void Handle(Func<Exception, bool> predicate)
        {
            List<Exception> failed = new List<Exception> ();
            foreach (var e in innerExceptions) {
                // Spicy Pixel: Mono is wrong here.
                // Bug filed: https://bugzilla.xamarin.com/show_bug.cgi?id=11867
                //
                // This is what MSDN says:
                //
                // http://msdn.microsoft.com/en-us/library/system.aggregateexception.handle.aspx
                // If any invocations of the predicate throws an exception, it will
                // halt the processing of any more exceptions and immediately propagate
                // the thrown exception as-is.
                //try {
                    if (!predicate (e))
                        failed.Add (e);
                //} catch {
                //	throw new AggregateException (failed);
                //}
            }
            if (failed.Count > 0)
                throw new AggregateException (failed);
        }

Usage Example

Esempio n. 1
0
 public static void Handle()
 {
     AggregateException ex = new AggregateException();
     ex = new AggregateException(new[] { new ArgumentException(), new ArgumentException(), new ArgumentException() });
     int handledCount = 0;
     ex.Handle((e) =>
     {
         if (e is ArgumentException)
         {
             handledCount++;
             return true;
         }
         return false;
     });
     Assert.Equal(handledCount, ex.InnerExceptions.Count);
 }
All Usage Examples Of System.AggregateException::Handle