public class ExceptionV5Throwing {
    public static Person retornoNulo() {
        return null;
    }
    public static void thrower() throws ArrayIndexOutOfBoundsException, NullPointerException {
        System.out.println("Me pregunto por donde petara. :-?");
        if (((int)(Math.random()*2)) == 1) {
            Person p = retornoNulo();
            if (p == null) {
                throw new NullPointerException();
            }
            System.out.println("Person: " + p);
            System.out.println("Person's first name: " + p.getFirstName());
        } else {
            int a[] = {1, 2, 3};
            for (int i=1; i<=3; i++) {
                if (i < 0 || i >= 3) {
                    throw new ArrayIndexOutOfBoundsException();
                }
                System.out.println("Access element " + i +" :" + a[i]);
            }
        }
    }
    public static void main(String[] args) {
        // thrower();
        try {
            thrower();
        } catch (ArrayIndexOutOfBoundsException|NullPointerException e) {
            System.out.println("Ups! Array o Pointer Exception:\n\t" + e);
            // Since Java 7 you can handle more than one exceptions
            // using a single catch block, this feature simplifies the code.
        }
        System.out.println("Me recupero y no peto. :-)");
    }
}
