Q:

Tracking the point until when the code ran

I need to track the point until when the code ran. Consider the program given below:
function f() throws Exception{
    statement 1 //can throw exception
    statement 2 //can throw exception
    statement 3 //can throw exception
}

I need a mechanism to identify at what point the exception occurred, one way is to do this using exceptions, i.e. creating a variable in exception itself, or pass something by reference to function f and use it to identify at what point did the function the ran successfully. 
Which is the better way, or is there any more elegant way to do this?

A:

A common mistake is to not print out the stack trace, or not print out the exception at all.  Don't do that in most cases, because you are throwing away useful information.
I would use the debugger to step through the code or find the exact point an exception is thrown, or you could read the stack trace for the exception.
public static void f() throws Exception {
    statement1(); //can throw exception line 101
    statement2(); //can throw exception line 102
    statement3(); //can throw exception line 103
}

When the stack trace says it threw an exception on line 101, 102 or 103, this tells you which statement it was executing.
If you need to do this at runtime, doing something different each time I would put each one in a try/catch block.
public static void f() throws Exception {
    try {
        statement1();
    } catch (TheException e) {
        doSomething1();
        // return or throw
    }
    try {
        statement2();
    } catch (TheException e) {
        doSomething2();
        // return or throw
    }
    try {
        statement3();
    } catch (TheException e) {
        doSomething3();
        // return or throw
    }
}

