Exploring Coverage Analysis Views > Setting Preferences for Coverage Views >  Filtering Out Catch Block Data  

Filtering Out Catch Block Data

The data for catch blocks is included in the following metrics:

• % Missed Lines

• Missed Lines

• Total Lines

• % Missed Conditions

• Missed Conditions

• Total Conditions

Catch blocks, however, are often impossible to test. If you choose not to test them, you may find it easier to interpret your results without the catch block data inflating the missed values. You can set a filter to remove the data from the calculations.

To filter out catch block data from calculations:

1 Select Window > Preferences.

2 Select JProbe > Coverage.

3 Select Filter out Catch Blocks.

4 Click OK.

When you return to a Coverage view, the calculations reflect the filter setting.

Exceptions

Although it is not generally considered good coding practice, it is possible that a line can have both normal statements and catch block statements.

Catch block filters do not apply in the followings situations:

Try and catch appear in the same line of code

try { Thread.sleep(1000); } catch (Exception e) {}

If Thread.sleep(1000) is executed, coverage is 100%; if not, coverage is 0%.

Executed code and catch appear in the same line of code

try {

    System.out.print(obj.toString());

    System.out.println(); } catch (Exception e) {

        System.exit(1); }

If System.out.print() is executed, the coverage is 100% regardless of whether or not it throws an exception.