public class FinallyStifleAndExit {
    
    public static String firstException() {
        try {
            String s = null;
            String t = s.toUpperCase();
            System.in.read();
        } catch (java.io.IOException e) {
            System.out.println("Catch 1");
            return ("Catch 1");
        } finally {
            System.out.println("Finally 1");
            return("Finally 1");
        }
    }
    
    public static String secondException() {
        try {
            String s = null;
            String t = s.toUpperCase();
        } catch (NullPointerException e) {
            System.out.println("Catch 2");
            return ("Catch 2");
        } finally {
            System.out.println("Finally 2");
            return("Finally 2");
        }
    }
    
    public static void thirdException() {
        try {
            String s = null;
            String t = s.toUpperCase();
        } catch (Exception e) {
            System.out.println("Catch 3");
            System.exit(-1);
        } finally {
            System.out.println("Finally 3");
        }        
    }

    public static void main(String[] args) {
        String result = firstException();
        System.out.println("If this prints, NullPointerException was stifled" +
                           " and result is " + result);
        result = secondException();        
        System.out.println("NullPointerException caught" +
                           " and result is " + result);
        thirdException();        
    }
}