如果代理实例的调用处理程序的 invoke 方法抛出一个经过检查的异常(不可分配给 RuntimeException 或 Error 的 Throwable),且该异常不可分配给该方法(在代理实例上调用该方法,并将其指派到调用处理程序)的 throws 子句中声明的任何异常类,则由代理实例上的方法调用抛出此异常。
关于异常信息的输出:
/** * ExceptionUtils位于commons-lang-2.4.jar */ import org.apache.commons.lang.exception.ExceptionUtils; import com.taobao.matrix.tejia.biz.manager.exception.ManagerException; class ManagerException extends Exception{ private static final long serialVersionUID = -2189493593216230677L; public ManagerException() { super(); } public ManagerException(String message, Throwable cause) { super(message, cause); } public ManagerException(String message) { super(message); } public ManagerException(Throwable cause) { super(cause); } } class ExceptionAO { public void createHouse() throws ManagerException { //这里异常信息为空 throw new ManagerException(); } } class ExceptionTest { public static void main(String[] args) { ExceptionAO exceptionAO=new ExceptionAO(); try { exceptionAO.createHouse(); } catch (Exception e) { e.printStackTrace(); //这种情况输出时为NULL的 System.out.println("msg:"+e.getMessage()); //这种则不一样,起码能输出子异常的类型 System.out.println("msge:"+ExceptionUtils.getRootCauseMessage(e)); } } }