ChainExcDemo.java Source code

Java tutorial

Introduction

Here is the source code for ChainExcDemo.java

Source

class ChainExcDemo {
    static void demoproc() {
        NullPointerException e = new NullPointerException("top layer");

        e.initCause(new ArithmeticException("cause"));

        throw e;
    }

    public static void main(String args[]) {
        try {
            demoproc();
        } catch (NullPointerException e) {
            System.out.println("Caught: " + e);

            System.out.println("Original cause: " + e.getCause());
        }
    }
}