java获取详细的异常链信息

xiaoxiao2021-02-27  289

package cn.goodbook.test; import java.io.PrintWriter; import java.io.StringWriter; import java.io.Writer; /** * 测试类 * * @author lgoodbook * @Date 2017年5月2日 上午11:07:47 * @version 1.0.0 */ public class Test { @SuppressWarnings("null") public static void main(String[] args) { String a2 = null; try { if(a2.equals("123")) { System.out.println(a2); } } catch (Exception e) { System.out.println("异常详情:"+getStackTrace(e.fillInStackTrace())); } } /** * 获取详细的异常链信息--精准定位异常位置 * * @param aThrowable * @return */ public static String getStackTrace(Throwable aThrowable) { final Writer result = new StringWriter(); final PrintWriter printWriter = new PrintWriter(result); aThrowable.printStackTrace(printWriter); return result.toString(); } }
转载请注明原文地址: https://www.6miu.com/read-6087.html

最新回复(0)