22

I don't get why emma doesn't give full code coverage to "finally" blocks. I've made a short example program to demonstrate this.

When I execute the program it shows:

try
finally

So I don't get why finally is marked as red (not executed) and the "finally" "println" is marked yellow (partially executed). Am I missing something? How to make emma understand that the finally block is covered?

example

Thank you!

stivlo
  • 83,644
  • 31
  • 142
  • 199

1 Answers1

16

There is an entry on this in the EMMA Faq: Implicit branches due to finally blocks. touching on the subject of partially covered finally blocks. Perhaps that helps.

aioobe
  • 413,195
  • 112
  • 811
  • 826
  • 2
    Thank you! In fact executing the code with and without exception inside the try block gives full coverage to the finally block. – stivlo Jan 30 '11 at 09:04
  • @stivlo Can you explain more? – JPM Oct 03 '12 at 16:16
  • 3
    @JPM The reason is written in the link provided by aioobe: *The compiler must ensure that the cleanup code [the finally block] is always executed, whether or not there is an exception thrown in the try block. There are thus two possible paths leading into the finally block: with and without an exception pending.* – stivlo Oct 03 '12 at 20:23