-
-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
Description
Add an option (and setting) to allow [Throws(typeof(Exception))]
as a catch the of the exceptions.
This would be useful in this case:
[Fact]
[Throws(
typeof(TrueException), typeof(NotNullException), typeof(EqualException), typeof(NotEmptyException),
typeof(Exception))]
public void Excample()
{
var str = "42";
var x = int.Parse(str);
Assert.True(true);
Assert.NotNull("foo");
Assert.NotEmpty([1]);
Assert.Equal("Hello world", str);
}
Implementation details
This settings would turn of the diagnostic:
Avoid declaring exception type 'System.Exception'; use a more specific exception type (THROW003)
And not flag any other declared exceptions with:
Exception already handled by declaration of super type ('Exception') (THROW008)
When exception type Exception
is declared. Effectively removing the type the inheritance hierarchy in this particular place.
Setting
Add to CheckedExceptions.settings.json
:
{
"treatThrowsExceptionAsCatchRest": true
}