⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 customexceptionhandler.java

📁 the musiccollection struts 1 application i netbeans implementation (strut for dummies book source)
💻 JAVA
字号:
/*
 * Created on Dec 18, 2003
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package dummies.struts.music;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ExceptionHandler;
import org.apache.struts.config.ExceptionConfig;

/**
 * @author Mike Robinson
 *
 */
public class CustomExceptionHandler extends ExceptionHandler
{
	Log log = LogFactory.getLog(CustomExceptionHandler.class);
	// commons logging reference

	/**
	 * Handle the exception. Standard execute method with addition of
	 * logging the stacktrace.
	 */
	public ActionForward execute(
		Exception ex,
		ExceptionConfig ae,
		ActionMapping mapping,
		ActionForm formInstance,
		HttpServletRequest request,
		HttpServletResponse response)
		throws ServletException
	{
		logExceptionChain(ex);
		return super.execute(ex, ae, mapping, formInstance, request, response);
	}

	/**
	 * logging exception stack trace, including chained exceptions
	 * modified from version by Keld H. Hansen
	 * http://javaboutique.internet.com/tutorials/Chained_Exceptions/
	 * 
	 * @param thr
	 */
	private void logExceptionChain(Throwable thr)
	{
		StackTraceElement[] s;
		Throwable t = thr;
		StringBuffer errorMsg = new StringBuffer("\nException chain (top to bottom):\n");
		while (t != null)
		{
			errorMsg.append("-------------------------------\n");
			s = t.getStackTrace();
			StackTraceElement s0 = s[0];
			errorMsg.append(t.toString());
			errorMsg.append("  at " + s0.toString() + "\n");
			if (t.getCause() == null)
			{
				errorMsg.append("-------------------------------\n");
				errorMsg.append("Complete traceback (bottom to top):\n");
				for (int i = 0; i < s.length; i++)
				errorMsg.append("  at " + s[i].toString() + "\n");
			}
			t = t.getCause();
		}
		log.error(errorMsg.toString());
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -