本文整理汇总了C#中System.AggregateException类的典型用法代码示例。如果您正苦于以下问题:C# AggregateException类的具体用法?C# AggregateException怎么用?C# AggregateException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AggregateException类属于System命名空间,在下文中一共展示了AggregateException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetAggregateExceptionMessages
private static IEnumerable<string> GetAggregateExceptionMessages(AggregateException exception)
{
foreach (var ie in exception.InnerExceptions)
{
yield return ie.Message;
}
}
开发者ID:Treetender,项目名称:Stocker,代码行数:7,代码来源:Program.cs
示例2: OnException
public override void OnException(HttpActionExecutedContext context)
{
Exception exp;
try
{
var logLevel = GetLogLevel(context.Exception);
_logException(context.Exception, logLevel);
var error = ToError(context.Exception);
var httpResponseMessage = new HttpResponseMessage
{
StatusCode = GetStatusCode(context.Exception),
ReasonPhrase = context.Exception.Message,
RequestMessage = context.Request,
Content = new ObjectContent<Error>(error, new JsonMediaTypeFormatter(), "application/json"),
};
exp = new HttpResponseException(httpResponseMessage);
}
catch (Exception exception)
{
var e = new AggregateException(exception, context.Exception);
_logException(e, LogLevel.SystemError);
throw;
}
throw exp;
}
开发者ID:Quilt4,项目名称:Quilt4.Service,代码行数:27,代码来源:ExceptionHandlingAttribute.cs
示例3: Should_flatten_aggregate_exceptions
public void Should_flatten_aggregate_exceptions()
{
var exception1 = new Exception("Exception 1", new Exception("Inner exception of exception 1"));
var exception2 = new Exception("Exception 2", new Exception("Inner exception of exception 2"));
var exception3 = new Exception("Exception 3", new Exception("Inner exception of exception 3"));
// Aggregate exceptions nested three levels deep.
var aggregate3 = new AggregateException(exception3);
var aggregate2 = new AggregateException(aggregate3, exception2);
var aggregate1 = new AggregateException(aggregate2, exception1);
var result = aggregate1.FlattenInnerExceptions();
Assert.IsType<AggregateException>(result);
// Only the inner exceptions of any aggregates should be returned. The inner exception
// of a non-aggregate should not be flattened.
var innerExceptions = ((AggregateException)result).InnerExceptions;
var expectedExceptions = new[] { exception1, exception2, exception3 };
Assert.Equal(3, innerExceptions.Count);
foreach (var exception in expectedExceptions)
Assert.True(innerExceptions.Contains(exception));
}
开发者ID:RadifMasud,项目名称:Nancy,代码行数:25,代码来源:ExceptionExtensionsFixture.cs
示例4: Exception
public void ExceptionPropertySetterHandlesAggregateExceptionsWithMultipleNestedExceptionsAndTrimsAfterReachingMaxCount()
{
const int Overage = 5;
List<Exception> innerExceptions = new List<Exception>();
for (int i = 0; i < Constants.MaxExceptionCountToSave + Overage; i++)
{
innerExceptions.Add(new Exception((i + 1).ToString(CultureInfo.InvariantCulture)));
}
AggregateException rootLevelException = new AggregateException("0", innerExceptions);
ExceptionTelemetry telemetry = new ExceptionTelemetry { Exception = rootLevelException };
Assert.Equal(Constants.MaxExceptionCountToSave + 1, telemetry.Exceptions.Count);
int counter = 0;
foreach (ExceptionDetails details in telemetry.Exceptions.Take(Constants.MaxExceptionCountToSave))
{
Assert.Equal(counter.ToString(CultureInfo.InvariantCulture), details.message);
counter++;
}
ExceptionDetails first = telemetry.Exceptions.First();
ExceptionDetails last = telemetry.Exceptions.Last();
Assert.Equal(first.id, last.outerId);
Assert.Equal(typeof(InnerExceptionCountExceededException).FullName, last.typeName);
Assert.Equal(
string.Format(
CultureInfo.InvariantCulture,
"The number of inner exceptions was {0} which is larger than {1}, the maximum number allowed during transmission. All but the first {1} have been dropped.",
1 + Constants.MaxExceptionCountToSave + Overage,
Constants.MaxExceptionCountToSave),
last.message);
}
开发者ID:ZeoAlliance,项目名称:ApplicationInsights-dotnet,代码行数:33,代码来源:ExceptionTelemetryTest.cs
示例5: Warn
private void Warn ()
{
try {
numReports += 1;
// Create a collection container to hold exceptions
List<Exception> exceptions = new List<Exception>();
// We have an exception with an innerexception, so add it to the list
exceptions.Add(new TimeoutException("This is part 1 of aggregate exception", new ArgumentException("ID missing")));
// Another exception, add to list
exceptions.Add(new NotImplementedException("This is part 2 of aggregate exception"));
// All done, now create the AggregateException and throw it
AggregateException aggEx = new AggregateException(exceptions);
throw aggEx;
} catch(Exception exp) {
Xamarin.Insights.Report(exp, new Dictionary <string, string> {
{"warning-local-time", DateTime.Now.ToString()}
}, Xamarin.Insights.Severity.Warning);
MessagingCenter.Send<TrackViewModel, string>(this, "Alert", "Warning registered");
}
}
开发者ID:moljac,项目名称:HolisticWare.Talks.MobilityDay.2015,代码行数:25,代码来源:TrackViewModel.cs
示例6: HandleException
public static void HandleException(AggregateException ex, Activity activity)
{
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.SetTitle("One or more Error(s)");
builder.SetMessage("First:" + ex.InnerExceptions.First().Message);
builder.Create().Show();
}
开发者ID:vishwanathsrikanth,项目名称:azureinsightmob,代码行数:7,代码来源:ExceptionHandler.cs
示例7: HandleRecursively
private static AggregateException HandleRecursively(
AggregateException aggregateException, Func<Exception, bool> predicate)
{
// Maintain a list of exceptions to be rethrown
List<Exception> innerExceptions = null;
// Loop over all of the inner exceptions
foreach (var inner in aggregateException.InnerExceptions)
{
// If the inner exception is itself an aggregate, process recursively
AggregateException innerAsAggregate = inner as AggregateException;
if (innerAsAggregate != null)
{
// Process recursively, and if we get back a new aggregate, store it
AggregateException newChildAggregate = HandleRecursively(innerAsAggregate, predicate);
if (newChildAggregate != null)
{
if (innerExceptions != null) innerExceptions = new List<Exception>();
innerExceptions.Add(newChildAggregate);
}
}
// Otherwise, if the exception does not match the filter, store it
else if (!predicate(inner))
{
if (innerExceptions != null) innerExceptions = new List<Exception>();
innerExceptions.Add(inner);
}
}
// If there are any remaining exceptions, return them in a new aggregate.
return innerExceptions.Count > 0 ?
new AggregateException(aggregateException.Message, innerExceptions) :
null;
}
开发者ID:Algorithman,项目名称:TestCellAO,代码行数:34,代码来源:AggregateExceptionExtensions.cs
示例8: StartAll
/// <summary>
/// Starts a list of tasks.
/// </summary>
/// <param name="tasks">The tasks to start.</param>
/// <param name="exceptions">The variable where to write the occurred exceptions to.</param>
/// <param name="scheduler">The custom scheduler to use.</param>
/// <returns>
/// The started tasks or <see langword="null" /> if <paramref name="tasks" /> is also <see langword="null" />.
/// </returns>
public static Task[] StartAll(
this IEnumerable<Task> tasks,
out AggregateException exceptions,
TaskScheduler scheduler = null)
{
exceptions = null;
if (tasks == null)
{
return null;
}
var occurredExceptions = new List<Exception>();
var startedTasks = new List<Task>();
try
{
using (var e = tasks.GetEnumerator())
{
while (e.MoveNext())
{
try
{
var t = e.Current;
if (t == null)
{
continue;
}
if (scheduler == null)
{
t.Start();
}
else
{
t.Start(scheduler);
}
startedTasks.Add(t);
}
catch (Exception ex)
{
occurredExceptions.Add(ex);
}
}
}
}
catch (Exception ex)
{
occurredExceptions.Add(ex);
}
if (occurredExceptions.Count > 0)
{
exceptions = new AggregateException(occurredExceptions);
}
return startedTasks.ToArray();
}
开发者ID:mkloubert,项目名称:Extensions.NET,代码行数:69,代码来源:Tasks.StartAll.cs
示例9: DumpException
static void DumpException(StringBuilder sb, int indent, AggregateException aggregateException)
{
AppendWithIndent(sb, indent, aggregateException);
foreach (var ex in aggregateException.InnerExceptions)
DumpException(sb, indent + 1, ex);
}
开发者ID:henricj,项目名称:phonesm,代码行数:7,代码来源:ExceptionExtensions.cs
示例10: HandleAggregateException
private void HandleAggregateException(AggregateException ex)
{
foreach (var innerException in ex.InnerExceptions)
{
_logger.Error("", innerException);
}
}
开发者ID:klaspersson,项目名称:musicapi,代码行数:7,代码来源:ExceptionLoggerFilterAttribute.cs
示例11: Stack_CreateFromAggregatedExceptionWithInnerException
public void Stack_CreateFromAggregatedExceptionWithInnerException()
{
bool caughtException = false;
try
{
File.Create(Path.GetInvalidFileNameChars()[0].ToString(), 0);
}
catch (ArgumentException exception)
{
var innerException1 = new InvalidOperationException("Test exception 1.");
var innerException2 = new InvalidOperationException("Test exception 2.", exception);
var aggregated = new AggregateException(innerException1, innerException2);
IList<Stack> stacks = Stack.CreateStacks(aggregated).ToList();
stacks.Count.Should().Be(4);
aggregated.StackTrace.Should().Be(null);
Assert.AreEqual("[No frames]", stacks[0].ToString());
Assert.AreEqual("[No frames]", stacks[1].ToString());
Assert.AreEqual("[No frames]", stacks[2].ToString());
Assert.AreEqual(exception.StackTrace, stacks[3].ToString());
Assert.AreEqual(aggregated.FormatMessage(), stacks[0].Message);
Assert.AreEqual(innerException1.FormatMessage(), stacks[1].Message);
Assert.AreEqual(innerException2.FormatMessage(), stacks[2].Message);
Assert.AreEqual(exception.FormatMessage(), stacks[3].Message);
caughtException = true;
}
Assert.IsTrue(caughtException);
}
开发者ID:Microsoft,项目名称:sarif-sdk,代码行数:33,代码来源:StackTests.cs
示例12: DoSomethingInPrivate
private async Task<string> DoSomethingInPrivate()
{
LogTo.Error("After do somehting in private task");
var list = new List<Exception>() { new NullReferenceException(), new ArgumentNullException() };
var aggregate = new AggregateException(list);
throw aggregate;
}
开发者ID:AnuragkAnkur,项目名称:Crappy,代码行数:7,代码来源:ExceptionThrower.cs
示例13: HandleException
private static void HandleException(AggregateException ex)
{
foreach (var x in ex.InnerExceptions)
{
Console.WriteLine(x.Message);
}
}
开发者ID:hkuntal,项目名称:TeamWorkManagement,代码行数:7,代码来源:Parallelism.cs
示例14: TraceAllErrors
public static void TraceAllErrors(string msg, AggregateException aggregateException)
{
foreach (Exception innerException in aggregateException.InnerExceptions)
{
Trace.TraceError("{0} Exception: {1}", msg, innerException);
}
}
开发者ID:ReubenBond,项目名称:Yams,代码行数:7,代码来源:TraceUtils.cs
示例15: MapMessageToErrorSchema
public Error MapMessageToErrorSchema(AggregateException exception, string correlationId, string messageType, string payload, MessageProperties properties, IDictionary<string, object> headers, MessageReceivedInfo info)
{
return new Error
{
errorDateTime = DateTime.Now,
errorType = ErrorTypeEnum.ApplicationError,
component = exception.InnerException.Source,
server = Environment.MachineName,
serviceName = messageType,
summary = exception.InnerException.Message,
detail = exception.InnerException.StackTrace,
original = new OriginalDetails
{
jobId = correlationId,
exchangeName = (info == null) ? string.Empty : info.Exchange,
queueName = (info == null) ? string.Empty : info.Queue,
payload = payload,
correlationId = correlationId,
routingKey = (info == null) ? string.Empty : info.RoutingKey,
deliveryMode = properties.DeliveryMode.ToString(),
headers = ConvertDictionaryToHeaderDetails(headers),
headerProperties = ConvertMessagePropertiesToHeaderDetails(properties)
}
};
}
开发者ID:jhonner72,项目名称:plat,代码行数:25,代码来源:CustomErrorHandling.cs
示例16: MessageDeserializationFailedQuarantinedEvent
public MessageDeserializationFailedQuarantinedEvent(AggregateException exceptions, string queueName, string storeName, Type messageType, byte[] data)
{
Exceptions = exceptions;
QueueName = queueName;
QuarantineStoreName = storeName;
MessageType = messageType;
Data = data;
}
开发者ID:rogierpennink,项目名称:lokad-cloud-storage,代码行数:8,代码来源:MessageDeserializationFailedQuarantinedEvent.cs
示例17: RaiseErrors
public void RaiseErrors()
{
if (exceptions.Count > 0)
{
AggregateException aggregate = new AggregateException(exceptions);
throw aggregate;
}
}
开发者ID:faugusto90,项目名称:DDD,代码行数:8,代码来源:BaseValidator.cs
示例18: LogAggregateException
public static void LogAggregateException(this ILog log, string message, AggregateException ex)
{
log.Error(message, ex);
foreach (Exception e in ex.InnerExceptions)
{
log.Error(e);
}
}
开发者ID:chuckfrazier,项目名称:DataPlatform,代码行数:8,代码来源:Log4netExtensions.cs
示例19: GenerateAggregateError
void GenerateAggregateError(IEnumerable<Exception> errors)
{
var message = new StringBuilder();
foreach (Exception ex in errors) {
message.AppendLine(ex.Message);
}
Error = new AggregateException(message.ToString(), errors);
}
开发者ID:lisiynos,项目名称:pascalabcnet,代码行数:8,代码来源:ServiceReferenceDiscoveryEventArgs.cs
示例20: An_insert_concurrency_exception_wrapped_in_an_exception_is_a_concurrency_exception
public void An_insert_concurrency_exception_wrapped_in_an_exception_is_a_concurrency_exception()
{
var exception =
new AggregateException(
new DataException("Cannot insert duplicate key"));
exception.IsConcurrencyException().Should().BeTrue();
}
开发者ID:KimberlyPhan,项目名称:Its.Cqrs,代码行数:8,代码来源:ExceptionExtensionsTests.cs
注:本文中的System.AggregateException类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论