Skip to content

RCS1140 - Don't require user to document exception types if caught in same method#1524

Merged
josefpihrt merged 11 commits intodotnet:mainfrom
Qluxzz:fix-required-to-document-caught-exceptions
Sep 27, 2024
Merged

RCS1140 - Don't require user to document exception types if caught in same method#1524
josefpihrt merged 11 commits intodotnet:mainfrom
Qluxzz:fix-required-to-document-caught-exceptions

Conversation

@Qluxzz
Copy link
Contributor

@Qluxzz Qluxzz commented Sep 15, 2024

There was no tests for RCS1140 so I added one based on the documentation for the rule.

When I was testing this rule I was not expecting it to require me to document exception types thrown but caught in the same method.

An example from a unit test I created

public void Foo(object parameter)
{
    try 
    {
        if (parameter == null)
            throw new ArgumentNullException(nameof(parameter));
    }
    catch (ArgumentNullException) {}
}

Here the exception is caught in the method but the analyzer for RCS1140 still require it to be documented on the method.

This PR checks if the exception type thrown in the method is also caught in the same method, and then removes the requirement to document it for the method.

@Qluxzz
Copy link
Contributor Author

Qluxzz commented Sep 15, 2024

@dotnet-policy-service agree

Copy link
Collaborator

@josefpihrt josefpihrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update changelog.

@Qluxzz Qluxzz requested a review from josefpihrt September 22, 2024 12:02
@Qluxzz Qluxzz requested a review from josefpihrt September 27, 2024 10:31
josefpihrt
josefpihrt previously approved these changes Sep 27, 2024
Copy link
Collaborator

@josefpihrt josefpihrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR! Thanks for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants