We have a practical test on Java about an IceCream shop. We need to handle exceptions in case no more stock. The code from the app below works fine. Exceptions are properly managed.

```
public class IceCreamApp2 {
    public static void main(String[] args) {
        Prijslijst priceList2 = new Prijslijst(2, 5, 8);

        Stock stock = new Stock(1, 8, 2, 1);

        IceCreamCar iceCar = new IceCreamCar(priceList2, stock);

        try {
            Eatable[] eatCar = {
                    iceCar.orderCone(new Cone.Flavor[]{Cone.Flavor.CHOCOLATE, Cone.Flavor.BANANA, Cone.Flavor.VANILLA}),
                    iceCar.orderCone(new Cone.Flavor[]{Cone.Flavor.VANILLA, Cone.Flavor.VANILLA}),
                    iceCar.orderMagnum(Magnum.MagnumType.ROMANTICSTRAWBERRIES),
                    iceCar.orderMagnum(Magnum.MagnumType.ALPINENUTS),
                    iceCar.orderIceRocket()
            };
            for (int i = 0; i < eatCar.length; i++) {
                eatCar[i].eat();
            }
            System.out.println(iceCar.getProfit());
        } catch (NoMoreIceCreamException noMoreIce) {
            System.out.println("No More Ice To sell... Beat it!!");
            System.out.println("Message: " + noMoreIce.getMessage());
            System.out.println("Cause: " + noMoreIce.getCause());
        }
        System.out.println(iceCar.getProfit());
    }
}

```

However this logic is flawded, since it stops counting the rest of order when an exception appears. Therefore Magnums and Icerockets, despite they 're in stock, are not counted in profit.
To do this, we know we need to loop through the table "Eatable". But it doesn't work and exit code 1 with the exception:

```
public class IceCreamApp2 {
    public static void main(String[] args) {
        Prijslijst priceList2 = new Prijslijst(2, 5, 8);

        Stock stock = new Stock(1, 8, 2, 1);

        IceCreamCar iceCar = new IceCreamCar(priceList2, stock);

        Eatable[] eatCar = {
                iceCar.orderCone(new Cone.Flavor[]{Cone.Flavor.CHOCOLATE, Cone.Flavor.BANANA, Cone.Flavor.VANILLA}),
                iceCar.orderCone(new Cone.Flavor[]{Cone.Flavor.VANILLA, Cone.Flavor.VANILLA}),
                iceCar.orderMagnum(Magnum.MagnumType.ROMANTICSTRAWBERRIES),
                iceCar.orderMagnum(Magnum.MagnumType.ALPINENUTS),
                iceCar.orderIceRocket()
        };

        for (int i = 0; i < eatCar.length; i++) {
            try {
                eatCar[i].eat();
            } catch (NoMoreIceCreamException noMoreIce) {
                System.out.println("No More Ice To sell... Beat it!!");
                System.out.println("Message: " + noMoreIce.getMessage());
                System.out.println("Cause: " + noMoreIce.getCause());
            }

        }
        System.out.println(iceCar.getProfit());
    }
}

```

Any clue what can be wrong ?