Java cvprof Coverage Report for
TryCatchFinally.java

    1   
    2   package uk.co.badgersinfoil.cvprof.example;
    3   
    4   public class TryCatchFinally {
    5   	private int a;
    6   	private boolean ok = false;
    7   
    8   	public void test() {
    9   		int temp = a;
   10   		try {
   11   			inTheEnd(null);
   12   		} catch (Exception e) {
   13   			// ignore that exception
   14   		}
   15   		if (a == temp) {
   16   			ok = true;
   17   		}
   18   	}
   19   
   20   	private int inTheEnd(String val) {
   21   		a++;
   22   		try {
   23   			return thrower(val);
   24   		} finally {
   25   			--a;
   26   		}
   27   	}
   28   
   29   	/**
   30   	 * The code in exception catch-blocks is sometimes overlooked in 
   31   	 * testing.  The coverage report will indicate this.
   32   	 */
   33   	private int thrower(String num) {
   34   		try {
   35   			return Integer.parseInt(num);
   36   		} catch (NullPointerException e) {
   37   			// this code doesn't get executed because passing null
   38   			// cases NumberFormatException, not NullPonterException
   39 > 			return 0;
   40   		}
   41   	}
   42   }