【Java开源代码栏目提醒】:网学会员在Java开源代码频道为大家收集整理了TryCatchTag.java提供大家参考,希望对大家有所帮助!
package ejavatags;
import javax.servlet.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.util.*;
public class TryCatchTag extends TagSupport implements TryCatchFinally
{
public int doStartTag()
throws JspException
{
return EVAL_PAGE;
}
public int doEndTag()
throws JspException
{
JspWriter out = pageContext.getOut();
try
{
boolean fake = true;
out.println("In end tag, about to throw exception.<br>");
if(fake) throw new Exception("On purpose exception.");
}
catch(Exception exp)
{
throw new JspException(exp);
}
return EVAL_PAGE;
}
public void doCatch(java.lang.Throwable t)
throws java.lang.Throwable
{
JspWriter out = pageContext.getOut();
try
{
out.println("Caught exception: "+t+"<br>");
}
catch(Exception exp)
{
throw new JspException(exp);
}
}
public void doFinally()
{
JspWriter out = pageContext.getOut();
try
{
out.println("In finally block.<br>");
}
catch(Exception exp)
{
//This method shouldn't throw exceptions.
}
}
}