import java.util.Random;

public class TestExceptions {
    static final Random random = new Random();

    public static void main(String[] args) {
        try {
            thisWillFail();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static void thisWillFail() throws Exception {
        try {
            methodOne();
        } catch (Exception e) {
            // throw new Exception("Oh, no!");
            throw new ApplicationException("Oh, no!", e);
        }
    }

    static void methodOne() throws Exception {
        if (random.nextGaussian() > 0.67) {
            throw new Exception();
        }
        methodTwo();
    }

    static void methodTwo() throws Exception {
        if (random.nextGaussian() > 0.43) {
            throw new Exception();
        }
        methodThree();
    }

    static void methodThree() throws Exception {
        if (random.nextGaussian() > 0.0) {
            throw new Exception();
        }
        methodFour();
    }

    static void methodFour() throws Exception {
        throw new Exception();
    }
}

