question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Closing bracket uncovered in try-catch statement when exception is re-thrown in catch

See original GitHub issue

The closing bracket is showing up as uncovered when I re-throw an exception from a catch statement. Is this expected behavior? The closing bracket is technically unreachable code, and it prevents me from reaching 100% coverage on the method when coverlet says it is uncovered by a test.

try
{
...
}
catch (Exception)
{
    // handle exception (retry/log/etc.)

    throw;
} // ** uncovered line **

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

2reactions
brprattcommented, Jun 11, 2019

This only seems to be an issue when there is an await inside the catch block. Here is a repro:

https://github.com/brpratt/CoverletAwaitThrowInsideCatch

From the generated code, it seems there is a branch while deciding how to re-throw the exception. In the linked example, maybe this is the offender?

Exception ex = <>s__1 as Exception;
if (ex == null)
{
    throw <>s__1;
}
ExceptionDispatchInfo.Capture(ex).Throw();
1reaction
NoahApplebaumcommented, Mar 7, 2020

Updated my coverlet.msbuild and it works! Thanks @MarcoRossignoli

Read more comments on GitHub >

github_iconTop Results From Across the Web

Closing bracket uncovered in try-catch statement when ...
The closing bracket is showing up as uncovered when I re-throw an exception from a catch statement. Is this expected behavior?
Read more >
java - Does the catch in try-with-resources cover the code ...
So yes, the exception will be caught by your catch block. Share.
Read more >
C++ Tutorial: Handling Exceptions - 2020
The catch keyword declares the exception handler. It follows immediately the closing brace of the try block. The format for catch is similar...
Read more >
What is Exception Handling? - SearchSoftwareQuality
The try bracket is used to contain the code that encounters the exception, so the application does not crash. The catch block is...
Read more >
Why are brackets required for try-catch?
To reiterate/summarize: the braces group together the statements controlled by the catch s, but do not group the catch s themselves. As such, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found