Java 中得到异常信息

来源:互联网 发布:海康威视mac客户端 编辑:程序博客网 时间:2024/05/29 04:16

Java开发中,遇到异常时,我们需要将异常的详细信息写入日志,以备查看。


public class ExceptionUtil {public static String getStackTrace(Throwable exp) {StringWriter sw = new StringWriter();PrintWriter pw = new PrintWriter(sw, true);exp.printStackTrace(pw);pw.flush();sw.flush();return sw.toString();}}


0 0
原创粉丝点击