@Test public void testGetMessageCustomExceptionAndMessage() { try { try { String s = null; s.toString(); } catch (Exception e) { throw new SystemException("自定义异常信息", e); } } catch (Exception e) { assertEquals(e.getMessage(), "空指针异常"); } }
public String getMessage(Throwable t) { String oldMessage; if (t instanceof InvocationTargetException) { oldMessage = getMessage(((InvocationTargetException) t).getTargetException()); } else if (t instanceof SystemException) { oldMessage = t.getMessage(); } else if (t instanceof SQLException) { oldMessage = getSQLException(t); } else if (t instanceof RuntimeException) { if (t.getMessage() != null) { oldMessage = t.getMessage(); } else if (null != t.getCause() && null != t.getCause().getMessage()) { oldMessage = t.getCause().getMessage(); } else { oldMessage = getCommonMessage(t); } } else { oldMessage = getCommonMessage(t); } return oldMessage; }
SystemException extends BaseSystemException { public String getMessage(Throwable t) { String oldMessage; if (t instanceof InvocationTargetException) { oldMessage = getMessage(((InvocationTargetException) t).getTargetException()); } else if (t instanceof SystemException) { oldMessage = t.getMessage(); } else if (t instanceof SQLException) { oldMessage = getSQLException(t); } else if (t instanceof RuntimeException) { if (t.getMessage() != null) { oldMessage = t.getMessage(); } else if (null != t.getCause() && null != t.getCause().getMessage()) { oldMessage = t.getCause().getMessage(); } else { oldMessage = getCommonMessage(t); } } else { oldMessage = getCommonMessage(t); } return oldMessage; } }
SystemException extends BaseSystemException { public String getMessage(Throwable t) { String oldMessage; if (t instanceof InvocationTargetException) { oldMessage = getMessage(((InvocationTargetException) t).getTargetException()); } else if (t instanceof SystemException) { oldMessage = t.getMessage(); } else if (t instanceof SQLException) { oldMessage = getSQLException(t); } else if (t instanceof RuntimeException) { if (t.getMessage() != null) { oldMessage = t.getMessage(); } else if (null != t.getCause() && null != t.getCause().getMessage()) { oldMessage = t.getCause().getMessage(); } else { oldMessage = getCommonMessage(t); } } else { oldMessage = getCommonMessage(t); } return oldMessage; } SystemException(String msg, Throwable t, String... args);  SystemException(String msg);  SystemException(Throwable t);  SystemException(String msg, Throwable t); }
SystemException extends BaseSystemException { public String getMessage(Throwable t) { String oldMessage; if (t instanceof InvocationTargetException) { oldMessage = getMessage(((InvocationTargetException) t).getTargetException()); } else if (t instanceof SystemException) { oldMessage = t.getMessage(); } else if (t instanceof SQLException) { oldMessage = getSQLException(t); } else if (t instanceof RuntimeException) { if (t.getMessage() != null) { oldMessage = t.getMessage(); } else if (null != t.getCause() && null != t.getCause().getMessage()) { oldMessage = t.getCause().getMessage(); } else { oldMessage = getCommonMessage(t); } } else { oldMessage = getCommonMessage(t); } return oldMessage; } SystemException(String msg, Throwable t, String... args);  SystemException(String msg);  SystemException(Throwable t);  SystemException(String msg, Throwable t); String getMessage(Throwable t); }
SystemException extends BaseSystemException { public String getMessage(Throwable t) { String oldMessage; if (t instanceof InvocationTargetException) { oldMessage = getMessage(((InvocationTargetException) t).getTargetException()); } else if (t instanceof SystemException) { oldMessage = t.getMessage(); } else if (t instanceof SQLException) { oldMessage = getSQLException(t); } else if (t instanceof RuntimeException) { if (t.getMessage() != null) { oldMessage = t.getMessage(); } else if (null != t.getCause() && null != t.getCause().getMessage()) { oldMessage = t.getCause().getMessage(); } else { oldMessage = getCommonMessage(t); } } else { oldMessage = getCommonMessage(t); } return oldMessage; } SystemException(String msg, Throwable t, String... args);  SystemException(String msg);  SystemException(Throwable t);  SystemException(String msg, Throwable t); String getMessage(Throwable t);  }