Why emma doesn't give full coverage to finally blocks?
Asked Answered
P

1

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!

Popele answered 30/1, 2011 at 8:17 Comment(0)
S
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.

Syndactyl answered 30/1, 2011 at 8:22 Comment(3)
Thank you! In fact executing the code with and without exception inside the try block gives full coverage to the finally block.Popele
@Popele Can you explain more?Iodometry
@Iodometry 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.Popele

© 2022 - 2024 — McMap. All rights reserved.