Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 15db7ab

Browse files
committed
Override AggregateException.Message to include more detail
ToString() includes details on inner exceptions, but Message does not, with the default message just saying "One or more errors occurred." This commit overrides Message to append the messages of the inner exceptions as well.
1 parent a31dbef commit 15db7ab

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/mscorlib/src/System/AggregateException.cs

+25
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System.Runtime.ExceptionServices;
1818
using System.Runtime.Serialization;
1919
using System.Security;
20+
using System.Text;
2021
using System.Threading;
2122

2223
namespace System
@@ -431,6 +432,30 @@ public AggregateException Flatten()
431432
return new AggregateException(Message, flattenedExceptions);
432433
}
433434

435+
/// <summary>Gets a message that describes the exception.</summary>
436+
public override string Message
437+
{
438+
get
439+
{
440+
if (m_innerExceptions.Count == 0)
441+
{
442+
return base.Message;
443+
}
444+
445+
StringBuilder sb = StringBuilderCache.Acquire();
446+
sb.Append(base.Message);
447+
sb.Append(' ');
448+
for (int i = 0; i < m_innerExceptions.Count; i++)
449+
{
450+
sb.Append('(');
451+
sb.Append(m_innerExceptions[i].Message);
452+
sb.Append(") ");
453+
}
454+
sb.Length -= 1;
455+
return StringBuilderCache.GetStringAndRelease(sb);
456+
}
457+
}
458+
434459
/// <summary>
435460
/// Creates and returns a string representation of the current <see cref="AggregateException"/>.
436461
/// </summary>

0 commit comments

Comments
 (0)