异常子类 public class UploadException extends BaseException {}
模拟的接口类: public class InterfaceClass { public void test() throws UploadException { try { throw new IOException(); }catch(IOException ioe) { //log the original exception UploadException ue = new UploadException(); ue.setRootCause(ioe); throw ue; } } }
前端程序: public class ClientClass { public static void main(String[] args) { try{ new InterfaceClass().test(); }catch(UploadException ue) { ue.printStackTrace(); } } }
org.test.util.exception.UploadException [java] at org. test.util.exception.InterfaceClass.test(InterfaceClass.java:13) [java] at org. test.util.exception.ClientClass.main(ClientClass.java:6) [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [java] at java.lang.reflect.Method.invoke(Method.java:324) … java.io.IOException [java] at org. test.util.exception.InterfaceClass.test(InterfaceClass.java:9) [java] at org. test.util.exception.ClientClass.main(ClientClass.java:6) [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [java] at java.lang.reflect.Method.invoke(Method.java:324)