Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public AggregateException Flatten()
while (exceptionsToFlatten.Count > nDequeueIndex)
{
// dequeue one from exceptionsToFlatten
IList<Exception> currentInnerExceptions = exceptionsToFlatten[nDequeueIndex++].InnerExceptions;
ReadOnlyCollection<Exception> currentInnerExceptions = exceptionsToFlatten[nDequeueIndex++].InnerExceptions;

for (int i = 0; i < currentInnerExceptions.Count; i++)
{
Expand All @@ -401,8 +401,7 @@ public AggregateException Flatten()
}
}


return new AggregateException(Message, flattenedExceptions);
return new AggregateException(GetType() == typeof(AggregateException) ? base.Message : Message, flattenedExceptions);
}

/// <summary>Gets a message that describes the exception.</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Xunit;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Xunit;

namespace System.Threading.Tasks.Tests
{
Expand Down Expand Up @@ -103,7 +101,9 @@ public static void Flatten()
Exception exceptionB = new Exception("B");
Exception exceptionC = new Exception("C");

AggregateException aggExceptionBase = new AggregateException(exceptionA, exceptionB, exceptionC);
AggregateException aggExceptionBase = new AggregateException("message", exceptionA, exceptionB, exceptionC);

Assert.Equal("message (A) (B) (C)", aggExceptionBase.Message);

// Verify flattening one with another.
// > Flattening (no recursion)...
Expand All @@ -114,15 +114,17 @@ public static void Flatten()
};

Assert.Equal(expected1, flattened1.InnerExceptions);
Assert.Equal("message (A) (B) (C)", flattened1.Message);

// Verify flattening one with another, accounting for recursion.
AggregateException aggExceptionRecurse = new AggregateException(aggExceptionBase, aggExceptionBase);
AggregateException aggExceptionRecurse = new AggregateException("message", aggExceptionBase, aggExceptionBase);
AggregateException flattened2 = aggExceptionRecurse.Flatten();
Exception[] expected2 = new Exception[] {
exceptionA, exceptionB, exceptionC, exceptionA, exceptionB, exceptionC,
};

Assert.Equal(expected2, flattened2.InnerExceptions);
Assert.Equal("message (A) (B) (C) (A) (B) (C)", flattened2.Message);
}
}
}