/** Flow Control and Exception Handling
    Jaworski pg 126 Question 15
*/

class Q5_15 {

    public static void main(String[] args) {
    
        for( int i=0; i<10; ++i ) {
            try{
                try {
                    if( i%3 == 0 ) throw new Exception("E0");
                    System.out.println(i);
                } catch (Exception inner) {
                    i *= 2;
                    if( i%3 == 0 ) throw new Exception("E1");
                } finally {
                    ++i;
                }
            
            } catch (Exception outer) {
                i += 3;
            } finally {
                --i;    
            }
        
        } // end for-loop
    
    }

/* What happens during processing:

i = 0
Exception EO thrown
catch: i = 0
       Exception E1 thrown
inner finally: i = 1
catch: i = 4
outer finnally: i = 3
loop: i = 4
prints 4
inner finally: i=5
outer finally: i = 4
loop: i = 5
prints 5
inner finally: i = 6
outer finally: i = 5
loop: i = 6
Exception EO thrown
catch: i = 12
i is greater than 10 thru rest of code
so loop stops     

*/

}
