public class ExceptionV6FinallyWithReturn {
    public static final int SUCCESS     = 1;
    public static final int ARRAY_EX    = 2;
    public static final int POINTER_EX  = 3;
    public static final int FINALLY     = 4;
    public static Person retornoNulo() {
        return null;
    }
    public static int letsTry() {
        try {
            System.out.println("Me pregunto por donde petara. :-?");
            if (((int)(Math.random()*2)) == 1) {
                Person p = retornoNulo();
                System.out.println("Person: " + p);
                System.out.println("Person's first name: " + p.getFirstName());
            } else {
                int a[] = {1, 2, 3};
                System.out.println("Access element two :" + a[2]);
                System.out.println("Access element three  :" + a[3]);
                System.out.println("Access element four  :" + a[4]);
            }
            return SUCCESS;
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("Ups! Array Exception:\n\t" + e);
            return ARRAY_EX;
        } catch (NullPointerException e) {
            System.out.println("Ups! Pointer Exception:\n\t" + e);
            return POINTER_EX;
        } finally {
            System.out.println("The finally statement is always executed");
            return FINALLY;
        }
    }
    public static void main(String[] args) {
        switch (letsTry()) {
            case SUCCESS:
                System.out.println("SUCCESS!!!");
                break;
            case ARRAY_EX:
                System.out.println("Array Exception.");
                break;
            case POINTER_EX:
                System.out.println("Pointer Exception.");
                break;
            case FINALLY:
                System.out.println("FINALLY!!!");
                break;
            default:
                System.out.println("No che.");
        }
    }
}
/*
 * Note the following:
 * - A catch clause cannot exist without a try statement.
 * - It is not compulsory to have finally clauses on a try/catch block.
 * - The try block cannot be present without either catch or finally.
 * - Any code cannot be present in between the try, catch, finally blocks.
 */
