Table of Contents

Class ExceptionExtensions

Namespace
Acuit.Pinpoint.Common.Extensions
Assembly
Acuit.Pinpoint.Common.dll

Extension methods for Exception.

public static class ExceptionExtensions
Inheritance
ExceptionExtensions
Inherited Members

Methods

ConcatMessagesHierarchy(Exception, string)

Flattens the inner exceptions hierarchy for an exception and returns all of the messages concatenated.

public static string ConcatMessagesHierarchy(this Exception exception, string separator = null)

Parameters

exception Exception

The exception.

separator string

The separator to use, or null to use NewLine.

Returns

string

The concatenated messages.

Remarks

MessagesHierarchyAsSingleLine(Exception) or MessagesHierarchyAsMultipleLines(Exception) is preferred when formatting messages for display.

Exceptions

ArgumentNullException

exception is null.

EnumerateFlattenedHierarchy(Exception)

Enumerates a flattened inner exceptions hierarchy for an exception.

public static IEnumerable<Exception> EnumerateFlattenedHierarchy(this Exception exception)

Parameters

exception Exception

The exception.

Returns

IEnumerable<Exception>

An enumerable of exception objects.

Remarks

For AggregateExceptions, all inner exceptions are traversed; for all other exception types, any inner exceptions are traversed.

Exceptions

ArgumentNullException

exception is null.

MessagesHierarchyAsMultipleLines(Exception)

Combines the messages from an exception and all inner exception(s) into a multiline string suitable for display.

public static string MessagesHierarchyAsMultipleLines(this Exception exception)

Parameters

exception Exception

The exception.

Returns

string

The formatted string.

Remarks

The Message value from all exceptions in the exception hierachy are combined into one line, with NewLine separating each exception message. For AggregateException exceptions, all inner exceptions are traversed; for all other exception types, InnerException is traversed.

The Message value from each AggregateException exceptions will not be included in the resulting string if it is the same as the default value for AggregateException.Message for the current thread culture (as it is a generic message like "One or more errors occurred.").

The extra line like "Parameter name: paramName" added to the Message value from ArgumentException exceptions will be stripped.

Exceptions

ArgumentNullException

exception is null.

MessagesHierarchyAsSingleLine(Exception)

Combines the messages from an exception and all inner exception(s) into a one-line string suitable for display.

public static string MessagesHierarchyAsSingleLine(this Exception exception)

Parameters

exception Exception

The exception.

Returns

string

The formatted string.

Remarks

The Message value from all exceptions in the exception hierachy are combined into one line, with a space separating each exception message (as each exception message is expected to be a complete sentence). For AggregateException exceptions, all inner exceptions are traversed; for all other exception types, InnerException is traversed.

The Message value from each AggregateException exceptions will not be included in the resulting string if it is the same as the default value for AggregateException.Message for the current thread culture (as it is a generic message like "One or more errors occurred.").

The extra line like "Parameter name: paramName" added to the Message value from ArgumentException exceptions will be stripped.

Any line breaks in exception messages will be converted to spaces.

Exceptions

ArgumentNullException

exception is null.

StripOuterAggregateException(Exception)

Strips an outer AggregateException exception if it wraps a single inner exception.

public static Exception StripOuterAggregateException(this Exception exception)

Parameters

exception Exception

The exception.

Returns

Exception

The InnerException of exception if it is an AggregateException that wraps a single inner exception; otherwise, returns exception.

Exceptions

ArgumentNullException

exception is null.