本文整理汇总了C#中System.AggregateException.Handle方法的典型用法代码示例。如果您正苦于以下问题:C# AggregateException.Handle方法的具体用法?C# AggregateException.Handle怎么用?C# AggregateException.Handle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.AggregateException
的用法示例。
在下文中一共展示了AggregateException.Handle方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Handle
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);
}
示例2: HandleInvalidCases
public static void HandleInvalidCases()
{
AggregateException ex = new AggregateException();
Assert.Throws<ArgumentNullException>(() => ex.Handle(null));
ex = new AggregateException(new[] { new Exception(), new ArgumentException(), new ArgumentException() });
int handledCount = 0;
Assert.Throws<AggregateException>(
() => ex.Handle((e) =>
{
if (e is ArgumentException)
{
handledCount++;
return true;
}
return false;
}));
}
示例3: ApnsBroker_OnNotificationFailed
private void ApnsBroker_OnNotificationFailed(ApnsNotification notification, AggregateException exception)
{
exception.Handle(ex =>
{
// See what kind of exception it was to further diagnose
if(ex is ApnsNotificationException)
{
var notificationException = ex as ApnsNotificationException;
// Deal with the failed notification
var apnsNotification = notificationException.Notification;
var statusCode = notificationException.ErrorStatusCode;
Debug.WriteLine($"Apple Notification Failed: ID={apnsNotification.Identifier}, Code={statusCode}");
}
else
{
// Inner exception might hold more useful information like an ApnsConnectionException
Debug.WriteLine($"Apple Notification Failed for some unknown reason : {ex.InnerException}");
}
// Mark it as handled
return true;
});
}
示例4: AssertLinkedInApiException
protected void AssertLinkedInApiException(AggregateException ae, string expectedMessage, LinkedInApiError error)
{
ae.Handle(ex =>
{
if (ex is LinkedInApiException)
{
Assert.AreEqual(expectedMessage, ex.Message);
Assert.AreEqual(error, ((LinkedInApiException)ex).Error);
return true;
}
return false;
});
}
示例5: GcmBroker_OnNotificationFailed
private void GcmBroker_OnNotificationFailed(GcmNotification notification, AggregateException exception)
{
exception.Handle(ex =>
{
// See what kind of exception it was to further diagnose
if(ex is GcmNotificationException)
{
var notificationException = ex as GcmNotificationException;
// Deal with the failed notification
var gcmNotification = notificationException.Notification;
var description = notificationException.Description;
Debug.WriteLine($"GCM Notification Failed: ID={gcmNotification.MessageId}, Desc={description}");
}
else if(ex is GcmMulticastResultException)
{
var multicastException = ex as GcmMulticastResultException;
foreach(var succeededNotification in multicastException.Succeeded)
{
Debug.WriteLine($"GCM Notification Failed: ID={succeededNotification.MessageId}");
}
foreach(var failedKvp in multicastException.Failed)
{
var n = failedKvp.Key;
var e = failedKvp.Value;
Debug.WriteLine($"GCM Notification Failed: ID={n.MessageId}, Desc={e.Message}");
}
}
else if(ex is DeviceSubscriptionExpiredException)
{
var expiredException = ex as DeviceSubscriptionExpiredException;
var oldId = expiredException.OldSubscriptionId;
var newId = expiredException.NewSubscriptionId;
Debug.WriteLine($"Device RegistrationId Expired: {oldId}");
if(!string.IsNullOrWhiteSpace(newId))
{
// If this value isn't null, our subscription changed and we should update our database
Debug.WriteLine($"Device RegistrationId Changed To: {newId}");
}
}
else if(ex is RetryAfterException)
{
var retryException = (RetryAfterException)ex;
// If you get rate limited, you should stop sending messages until after the RetryAfterUtc date
Debug.WriteLine($"GCM Rate Limited, don't send more until after {retryException.RetryAfterUtc}");
}
else
{
Debug.WriteLine("GCM Notification Failed for some unknown reason");
}
// Mark it as handled
return true;
});
}
示例6: HandleDatabaseException
private void HandleDatabaseException(AggregateException exception)
{
exception.Handle(e =>
{
if (!(e is Domain.Exceptions.DomainValidationException))
{
_logger.Log(Level.Error, "Data operation failed to successfully complete, exception: {0}.", e.GetType().Name);
MessengerInstance.Send<DialogMessage>(new DialogMessage("An error occured and the test was not saved", msg => { }));
}
return true;
});
}
示例7: AssertDropboxApiException
// tests helpers
#if NET_4_0 || SILVERLIGHT_5
private void AssertDropboxApiException(AggregateException ae, string expectedMessage, DropboxApiError error)
{
ae.Handle(ex =>
{
if (ex is DropboxApiException)
{
Assert.AreEqual(expectedMessage, ex.Message);
Assert.AreEqual(error, ((DropboxApiException)ex).Error);
return true;
}
return false;
});
}
示例8: AggregateExceptionToString
/// <summary>
/// Converts an AggregateException to a printable form, including inner exceptions etc.
/// </summary>
public static string AggregateExceptionToString(AggregateException aex, bool includeStackTrace)
{
var sb = new StringBuilder();
aex.Handle(ex =>
{
if (ex is TargetInvocationException)
{
while (ex.InnerException != null)
{
sb.Append(ex.InnerException.Message + "\n");
if (includeStackTrace) sb.Append(ex.InnerException.StackTrace + "\n");
ex = ex.InnerException;
}
}
else
{
sb.Append(ex.Message + "\n");
if (includeStackTrace) sb.Append(ex.StackTrace + "\n");
}
return true;
});
return sb.ToString();
}
示例9: _HandleException
private void _HandleException(AggregateException e)
{
e.Handle((ex) =>
{
Debug.WriteLine(e);
return true;
});
}