Class ExceptionAggregator
Aggregates exceptions. Intended to run one or more code blocks, and collect the exceptions thrown by those code blocks.
Namespace: Xunit.Sdk
Assembly: xunit.core.dll
Syntax
public class ExceptionAggregator : object
Constructors
| Improve this Doc View SourceExceptionAggregator()
Initializes a new instance of the ExceptionAggregator class.
Declaration
public ExceptionAggregator()
ExceptionAggregator(ExceptionAggregator)
Initializes a new instance of the ExceptionAggregator class that contains the exception list of its parent.
Declaration
public ExceptionAggregator(ExceptionAggregator parent)
Parameters
Type | Name | Description |
---|---|---|
ExceptionAggregator | parent | The parent aggregator to copy exceptions from. |
Properties
| Improve this Doc View SourceHasExceptions
Returns true
if the aggregator has at least one exception inside it.
Declaration
public bool HasExceptions { get; }
Property Value
Type | Description |
---|---|
Boolean |
Methods
| Improve this Doc View SourceAdd(Exception)
Adds an exception to the aggregator.
Declaration
public void Add(Exception ex)
Parameters
Type | Name | Description |
---|---|---|
Exception | ex | The exception to be added. |
Aggregate(ExceptionAggregator)
Adds exceptions from another aggregator into this aggregator.
Declaration
public void Aggregate(ExceptionAggregator aggregator)
Parameters
Type | Name | Description |
---|---|---|
ExceptionAggregator | aggregator | The aggregator whose exceptions should be copied. |
Clear()
Clears the aggregator.
Declaration
public void Clear()
Run(Action)
Runs the code, catching the exception that is thrown and adding it to the aggregate.
Declaration
public void Run(Action code)
Parameters
Type | Name | Description |
---|---|---|
Action | code | The code to be run. |
RunAsync(Func<Task>)
Runs the code, catching the exception that is thrown and adding it to the aggregate.
Declaration
public Task RunAsync(Func<Task> code)
Parameters
Type | Name | Description |
---|---|---|
Func<Task> | code | The code to be run. |
Returns
Type | Description |
---|---|
Task |
RunAsync<T>(Func<Task<T>>)
Runs the code, catching the exception that is thrown and adding it to the aggregate.
Declaration
public Task<T> RunAsync<T>(Func<Task<T>> code)
Parameters
Type | Name | Description |
---|---|---|
Func<Task<T>> | code | The code to be run. |
Returns
Type | Description |
---|---|
Task<T> |
Type Parameters
Name | Description |
---|---|
T |
ToException()
Returns an exception that represents the exceptions thrown by the code passed to the Run(Action) or RunAsync(Func<Task>) method.
Declaration
public Exception ToException()
Returns
Type | Description |
---|---|
Exception | Returns |