dotnet / roslynator

Roslynator is a set of code analysis tools for C#, powered by Roslyn.
https://josefpihrt.github.io/docs/roslynator
Other
3.1k stars 261 forks source link

RCS1140 throws an ArgumentNullException in try/catch when exception is not used #1553

Closed merlinschumacher closed 1 month ago

merlinschumacher commented 1 month ago

Rosylnator Analyzers 4.12.7:

Steps to Reproduce: Create a custom exception, use the custom exception in a try/catch, where you don't use the exception.

Here is an example project: https://github.com/merlinschumacher/Roslyn-RCS1140-Issue

With 4.12.6 the issue isn't present.

Actual Behavior: This triggers an argument null exception. Independent of the presence of an XML comment for the exception:

            try
            {
                Method2();
            }
            catch
            {
                throw new MyCustomException("MyCustomException");
            }

This works (passing the caught exception is not necessary):

            try
            {
                Method2();
            }
            catch (Exception ex)
            {
                throw new MyCustomException("MyCustomException");
            }

Expected Behavior: To create an analyzer message notifying me of the possibly missing XML comment.