java很老的web工程重构,加入详细异常链信息分析

下面是调用链的控制台输出方法:

// === 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);

。。。。。

}

相关推荐
山东孙燕姿1 小时前
设备台账重构:从一张表到三层模型
android·java·网络·低代码·重构·rxjava
萧瑟余晖1 小时前
Spring缓存抽象详解
java·spring·缓存
贾伟康1 小时前
【共创稿事节】一个 UserDataManager 管八类数据:Preferences 持久化的克制用法
java·服务器·前端·harmonyos·arkts·鸿蒙
卓豪终端管理2 小时前
【无标题】
java·服务器·前端
智_永无止境2 小时前
又找到一个纯Java的OCR项目,识别的格式还挺多
java·开发语言·ocr
学编程就要猛2 小时前
MCP(Model Context Protocol)
java·springai
用户072367066602 小时前
Apollo 配置热更新落地:让 Spring Boot @ConfigurationProperties Bean 不重启即时生效
java
2601_970703832 小时前
中国除湿机与湿度控制行业研究报告
java·大数据·人工智能
深入云栈2 小时前
Netty 4.2.x 源码深度解析 (二十一):Pipeline 事件传播 —— Inbound 与 Outbound 的双向流转
java·后端·架构