下面是调用链的控制台输出方法:
// === TEMP DEBUG (2026-10-27): print full exception chain incl. SQLException vendorCode ===
private static void dumpChain(Throwable t) {
System.err.println("==== EXCEPTION CHAIN START ====");
int d = 0;
Throwable cur = t;
java.sql.SQLException pendingNext = null;
while ((cur != null || pendingNext != null) && d < 15) {
if (cur == null) { cur = pendingNext; pendingNext = null; }
System.err.println("" + d + " " + cur.getClass().getName() + ": " + cur.getMessage());
Throwable next = cur.getCause();
if (cur instanceof com.sfgl.app.AppException) {
com.sfgl.app.AppException ape = (com.sfgl.app.AppException) cur;
System.err.println(" AppException.userMsg=" + ape.getUserMessage() + "");
System.err.println(" AppException.debugMsg=" + ape.getDebugMessage() + "");
Exception orig = ape.getException();
if (orig != null && orig != cur) {
System.err.println(" AppException.stored-exception -> " + orig.getClass().getName());
if (next == null) next = orig;
}
}
if (cur instanceof java.sql.SQLException) {
java.sql.SQLException se = (java.sql.SQLException) cur;
System.err.println(" vendorCode=" + se.getErrorCode() + " sqlState=" + se.getSQLState());
if (pendingNext == null) {
java.sql.SQLException nx = se.getNextException();
if (nx != null && nx != se) pendingNext = nx;
}
}
StackTraceElement\[\] st = cur.getStackTrace();
for (int i = 0; i < Math.min(st.length, 25); i++) {
System.err.println(" at " + sti);
}
cur = (pendingNext != null) ? pendingNext : next;
if (pendingNext != null) pendingNext = null;
d++;
}
System.err.println("==== EXCEPTION CHAIN END ====");
}
// === END TEMP DEBUG ===
调用方法例子:
try {
。。。。
}
catch (AppException ae) {
dumpChain(ae);
。。。。。
}