package W08H01_UsingExceptions;

public class ExceptionV3MultipleCatch {

    public static Person retornoNulo() {
        return null;
    }

    public static void main(String[] args) {
        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 fourS  :" + a[4]);
            }
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("Ups! Array Exception:\n\t" + e);
        } catch (NullPointerException e) {
            System.out.println("Ups! Pointer Exception:\n\t" + e);
        }
        System.out.println("Me recupero y no peto. :-)");
    }
}
