//自定义异常TestException
@SuppressWarnings("serial")
class TestException extends Exception{
public TestException(String msg){
super(msg);
}
}
public class ExceptionOne{
public void test1(String msg)throws TestException{
throw new TestException(msg);
}
public void test2()throws Throwable{
try{
test1("test1出现异常!");
}catch(TestException e){
RuntimeException oneExe=new RuntimeException("test2出现异常");
throw oneExe.initCause(e);
}
}
public static void main(String[] args)throws Throwable{
ExceptionOne newExe=new ExceptionOne();
newExe.test2();
}
}
结果: