Online Java Compiler By
JavaTpoint.com
import java.io.IOException; public class ThrowableInitCauseExample1 { public static void main(String[] args) throws Exception { try{ throwableTest(); }catch(Exception e){ System.err.println("Cause : "+e.getCause()); } } public static void throwableTest() throws Exception{ try{ int i=4/0; }catch(ArithmeticException ae){ IOException ioe = new IOException(); ioe.initCause(ae); throw ioe; } } }
Output