package com.crm.mess.util; /** * * @author liangrui * @2015/1/12 * */ public class ExceptionsLog { public synchronized static String logClzInfo(Exception e) { StringBuffer sb = new StringBuffer(); sb.append(e.getClass() + " " + e.getMessage() + "\n"); StackTraceElement[] stackTraceElement = e.getStackTrace(); for (StackTraceElement traceElement : stackTraceElement) { sb.append("\tat " + traceElement + "\n"); } return sb.toString(); } }
package org.pass; public class GetClz { public static void main(String[] args) { c(); } public static void c() { try { int c = 10 / 0; } catch (Exception e) { String estr = ExceptionsLog.logClzInfo(e); System.out.println("estr" + ":" + estr); e.printStackTrace(); } } } /*output: * * java.lang.ArithmeticException: / by zero at org.pass.GetClz.c(GetClz.java:13) at org.pass.GetClz.main(GetClz.java:5) estr:class java.lang.ArithmeticException / by zero at org.pass.GetClz.c(GetClz.java:13) at org.pass.GetClz.main(GetClz.java:5) * */
时间: 2024-10-29 22:04:56