---
title: "java获取异常stack详情"
author: "javaEEdevelop"
date: "2012-11-19T11:55:22Z"
tags: []
categories: ["开源软件"]
slug: "java-stack"
draft: false
lastmod: "2012-11-19T11:55:22Z"
id: 1729402
url: "https://javaeedevelop.iteye.com/blog/1729402"
---

```
/**
	 * 获取exception详情信息
	 * 
	 * @param e
	 *            Excetipn type
	 * @return String type
	 */
	public static String getExceptionDetail(Exception e) {

		StringBuffer msg = new StringBuffer("null");

		if (e != null) {
			msg = new StringBuffer("");

			String message = e.toString();

			int length = e.getStackTrace().length;

			if (length > 0) {

				msg.append(message + "\n");

				for (int i = 0; i < length; i++) {

					msg.append("\t" + e.getStackTrace()[i] + "\n");

				}
			} else {

				msg.append(message);
			}

		}
		return msg.toString();

	}
```