private static String concatMessages(AggregateException ae) { if (ae == null) { return ""; } var flattened = ae.Flatten(); return String.Join("\n\n", from exc in flattened.InnerExceptions select getExceptionMessages("", exc)); }
internal static string GetAggrateException(AggregateException ex) { StringBuilder sb = new StringBuilder(); sb.AppendLine(string.Join(" ", ex.Message, ex.StackTrace)); foreach (var innerEx in ex.Flatten().InnerExceptions) { sb.AppendLine(GetExceptionString(ex)); } return sb.ToString(); }
private static void ParseExceptionMessage(StringBuilder sb, AggregateException aex) { if (aex != null) { ParseCommonExceptionMessage(sb, aex); sb.AppendLine(); sb.AppendLine(); sb.AppendLine("InnerExceptions :"); sb.Append("==============================="); aex.Flatten().Handle((ex) => { ParseAllExceptionMessage(sb, ex); sb.AppendLine(); return true; }); } }
// // Methods // public AggregateException Flatten() { List <Exception> list = new List <Exception>(); foreach (Exception current in this.InnerExceptions) { AggregateException ex = current as AggregateException; if (ex != null) { list.AddRange(ex.Flatten().InnerExceptions); } else { list.Add(current); } } return(new AggregateException(list)); }
public void FinishRebuildAll(TaskStatus status, AggregateException exception) { _writeline($"Finished RebuildAll with status {status}"); if (exception != null) { var flattened = exception.Flatten(); foreach (var ex in flattened.InnerExceptions) { _writeline(""); _writeline("---------"); _writeline("Exception:"); _writeline("---------"); _writeline(ex.ToString()); _writeline(""); } } }
public AggregateException Flatten() { List <Exception> inner = new List <Exception> (); foreach (Exception e in innerExceptions) { AggregateException aggEx = e as AggregateException; if (aggEx != null) { inner.AddRange(aggEx.Flatten().InnerExceptions); } else { inner.Add(e); } } return(new AggregateException(inner)); }
public NugetProblem AddProblem(AggregateException aggregate) { var message = "Fatal error"; Exception exception = aggregate; if (aggregate != null) { exception = aggregate.Flatten(); message = exception.Message; if (exception.InnerException != null) { exception = exception.InnerException; message = exception.Message; } } var problem = new NugetProblem(message, exception); AddProblem(problem); return problem; }
public static void Flatten() { Exception exceptionA = new Exception("A"); Exception exceptionB = new Exception("B"); Exception exceptionC = new Exception("C"); AggregateException aggExceptionBase = new AggregateException(exceptionA, exceptionB, exceptionC); // Verify flattening one with another. // > Flattening (no recursion)... AggregateException flattened1 = aggExceptionBase.Flatten(); Exception[] expected1 = new Exception[] { exceptionA, exceptionB, exceptionC }; Assert.Equal(expected1, flattened1.InnerExceptions); // Verify flattening one with another, accounting for recursion. AggregateException aggExceptionRecurse = new AggregateException(aggExceptionBase, aggExceptionBase); AggregateException flattened2 = aggExceptionRecurse.Flatten(); Exception[] expected2 = new Exception[] { exceptionA, exceptionB, exceptionC, exceptionA, exceptionB, exceptionC, }; Assert.Equal(expected2, flattened2.InnerExceptions); }
private void FileErrored(ProcessingFile processingFile, AggregateException exception) { Logger.Error(string.Format("File processing failed: {0}", processingFile.OriginalFilePath), exception.Flatten()); this.processResultHandler.Handle(FileProcessResult.Error, processingFile); }
static Exception FindException(AggregateException exception) { foreach (var e in exception.Flatten().InnerExceptions) { if (e is Win32Exception) return e; var ce = e as CompositionException; if (ce != null) { var found = FindException(ce); if (found != null) return found; } if (!(e is XamlException)) continue; var inner = e.FindInnerException<Win32Exception>(); if (inner != null) return inner; } return null; }
/// <summary> /// Processes all exceptions inside an <see cref="AggregateException"/> and writes each inner exception to the console. /// </summary> /// <param name="aggregateException">The <see cref="AggregateException"/> to process.</param> public static void PrintAggregateException(AggregateException aggregateException) { // Flatten the aggregate and iterate over its inner exceptions, printing each foreach (Exception exception in aggregateException.Flatten().InnerExceptions) { Console.WriteLine(exception.ToString()); Console.WriteLine(); } }
private static void DumpException(AggregateException ex, StreamWriter sw, string header) { AggregateException flat = ex.Flatten(); if (header != null) { sw.WriteLine("Custom header message:"); sw.WriteLine(header); sw.WriteLine("---"); } sw.WriteLine("Aggregate Exception: " + ex.Message); sw.WriteLine("---"); foreach (Exception eo in ex.InnerExceptions) { DumpException(eo, sw, null); } }
/// <summary> /// Exception handler for the connection class /// </summary> /// <param name="exception"></param> public static void HandleException(AggregateException exception) { if (exception == null) return; foreach (var ex in exception.Flatten().InnerExceptions) { Log(ex.StackTrace); } }