Skip to content

[Feature Request] Throw overload that takes an argument #1629

@lonix1

Description

@lonix1

Background

I can assert that an action throws, using a generic parameter:

action.Should().Throw<SomeException>();

Feature Request

Please consider adding an overload that takes an instance as well:

action.Should().Throw(expectedType);

This would be very useful when I don't know the type at compile time.

Right now we need to use an ugly workaround:

try {
  action();
}
catch (Exception e) {
  e.Should().BeOfType(expectedType);
}

Versions

  • Which version of Fluent Assertions are you using? 5.10.3
  • Which .NET runtime and version are you targeting? 5.0.301

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions