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

。。。。。

}

相关推荐
Flynt13 小时前
掘金热文说 Spring Boot 4.1 默认开虚拟线程,我实测后发现了更狠的坑
java·spring boot·性能优化
Resean022314 小时前
Spring 源码分析(一)IOC 容器总览与 refresh() 全景
java·后端·spring
保利威视频SaaS小张14 小时前
企业直播接入笔记 12|企业内训直播怎么做签到和学时统计,防挂机这件事比想象中难
java·前端·数据库·笔记·视频云·polvy·polyv
dahaihua33315 小时前
用 SysML 表达航电系统架构(附建模示例)
设计模式·重构·系统架构·集成测试·需求分析·学习方法
顧棟16 小时前
【ES实战】 索引模板「可追溯、可校验」:一种模板治理的工程化思路
java·数据库·elasticsearch
玄昌盛不会编程17 小时前
LeetCode——2243. 计算字符串的数字和
java·算法·leetcode
AI导出鸭PC端17 小时前
纳米AI怎么复制表格?对话导出总是格式崩塌,我用“AI 导出鸭”重构了工作流
人工智能·重构·豆包·ai导出鸭
文丑颜不良啊17 小时前
LeetCode3061~3080题目解析
java·leetcode
装不满的克莱因瓶17 小时前
【AI时代必学】一篇文章教会你从零搭建Serverless架构
java·人工智能·ai·云原生·架构·serverless
七夜zippoe19 小时前
多轮对话管理:Session/记忆在 Java 后端怎么存(存储设计实战)
java·开发语言·ai·session·记忆