class FormatUmurSalahException extends RuntimeException {
    FormatUmurSalahException(String pesan, Throwable cause) {
        super(pesan, cause);
    }
}

public class ChainingDasar {
    static int bacaUmur(String teks) {
        try {
            return Integer.parseInt(teks);
        } catch (NumberFormatException e) {
            throw new FormatUmurSalahException(
                    "umur harus berupa angka, diterima: \"" + teks + "\"", e);
        }
    }

    public static void main(String[] args) {
        try {
            System.out.println("umur: " + bacaUmur("dua belas"));
        } catch (FormatUmurSalahException e) {
            System.out.println("lapisan aplikasi: " + e.getMessage());
            Throwable penyebab = e.getCause();
            System.out.println("penyebab        : " + penyebab.getClass().getSimpleName()
                    + " -> " + penyebab.getMessage());
        }
    }
}
