Online Java Compiler By
JavaTpoint.com
import java.lang.Throwable; public class ThrowableGetStackTraceExample2 { public static void function1() throws Exception{ throw new Exception(); } public static void function2() throws Throwable{ try{ function1(); }catch(Exception e){ throw e.fillInStackTrace(); } } public static void main(String[] args) throws Throwable { try{ function2(); }catch(Exception e){ System.err.println("Caught inside Main:"); StackTraceElement[] trace = e.getStackTrace(); System.err.println(trace[0].toString()); System.err.println(trace[1].toString()); } } }
Output