title: No C# Exception code coverage in SonarCloud
body: <p>We are using SonarCloud for code analysis in Azure DevOps on a C# .NET Core application.</p>
  <p>There is a recurring issue with lines throwing exceptions showing as uncovered, as shown below</p>
  <p><a href="https://i.stack.imgur.com/GdwcT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GdwcT.png" alt="SonarCloud code coverage" /></a></p>
  <p>The total code coverage for this file is shown as 36.8%, with all of the thrown exceptions being highlighted as uncovered.</p>
  <p>However, these exceptions are being explicitly tested in a test file using xUnit:</p>
  <pre><code>[Fact]
  public void It_should_not_allow_empty_importance_value()
  {
      try
      {
          _validator.ValidateImportance(&quot;&quot;, 0);
      }
      catch (FileFormatException ex)
      {
          Assert.Equal(&quot;Missing importance value in row 1&quot;, ex.Message);
      }            
  }
  </code></pre>
  <p>the ‘Assert.Throws’ assertion was also used:</p>
  <pre><code>[Fact]
  public void It_should_not_allow_empty_importance_value()
  {
      Assert.Throws&lt;FileFormatException&gt;(() =&gt; _validator.ValidateImportance(&quot;&quot;, 0));           
  }
  </code></pre>
  <p>Inspecting the .coverage file generated by the build pipeline showed this file as 100% covered:</p>
  <p><a href="https://i.stack.imgur.com/Heu4g.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Heu4g.png" alt="Coverage report" /></a></p>
  <p>The Prepare Analysis Configuration task is configured as follows, excluding certain files from analysis:</p>
  <pre><code># Additional properties that will be passed to the scanner, 
  # Put one key=value per line, example:
  sonar.exclusions=**/*.bin,**/WebApi/Migrations/*,**Tests.Unit/*,**Tests.Integration/*,**/WebApi/Extensions/EfCoreExtensions.cs
  sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/TestResults/*.trx
  </code></pre>
  <p>Running the tests locally returns 100% coverage for the given file.</p>
  <p>Is there an issue with C# code coverage of exceptions? This has been an issue throughout the project where thrown exceptions are shown as not being covered.</p>
  <p>Please let me know if any additional information is needed. Any suggestions are appreciated. Thanks!</p>