Skip to content

Document async exception handling with ThrowsAsync #425

@vbreuss

Description

@vbreuss

Description

The .ThrowsAsync<TException>() method is missing from the async documentation.

Missing Documentation

  • .ThrowsAsync<TException>() - Throw exceptions from async methods
  • Variants with exception factories

Suggested Documentation

Add to the "Async Methods" subsection under Method Setup:

**Async Exception Handling**

Throw exceptions from async methods:

```csharp
sut.SetupMock.Method.DispenseAsync(It.Is(\"Invalid\"), It.IsAny<int>())
    .ThrowsAsync<InvalidOperationException>();

// Or with a specific exception
sut.SetupMock.Method.DispenseAsync(It.Is(\"Error\"), It.IsAny<int>())
    .ThrowsAsync(new InvalidChocolateException(\"Bad chocolate!\"));

// Or with a factory
sut.SetupMock.Method.DispenseAsync(It.IsAny<string>(), It.IsAny<int>())
    .ThrowsAsync((type, amount) => new Exception($\"Cannot dispense {amount} {type}\"));

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationstate: releasedThe issue is released

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions