TryCatchFinally (Java EE 5)

Java EE API


javax.servlet.jsp.tagext Interface TryCatchFinally


public interface TryCatchFinally


想使用其他挂钩 (hook) 管理资源的 Tag、IterationTag 或 BodyTag 标记处理程序的辅助接口。

此接口提供了两个新方法:doCatch(Throwable) 和 doFinally()。原型调用如下所示:

h = get a Tag();  // get a tag handler, perhaps from pool

h.setPageContext(pc);  // initialize as desired
h.setParent(null);
h.setFoo("foo");
 
// tag invocation protocol; see Tag.java
try {
doStartTag()...
   ....
doEndTag()...
} catch (Throwable t) {
// react to exceptional condition
h.doCatch(t);
} finally {
// restore data invariants and release per-invocation resources
h.doFinally();
 }
 
... other invocations perhaps with some new setters
 ...
h.release();  // release long-term resources
 
英文文档:

The auxiliary interface of a Tag, IterationTag or BodyTag tag handler that wants additional hooks for managing resources.

This interface provides two new methods: doCatch(Throwable) and doFinally(). The prototypical invocation is as follows:

 h = get a Tag();  // get a tag handler, perhaps from pool

 h.setPageContext(pc);  // initialize as desired
 h.setParent(null);
 h.setFoo("foo");
 
 // tag invocation protocol; see Tag.java
 try {
   doStartTag()...
   ....
   doEndTag()...
 } catch (Throwable t) {
   // react to exceptional condition
   h.doCatch(t);
 } finally {
   // restore data invariants and release per-invocation resources
   h.doFinally();
 }
 
 ... other invocations perhaps with some new setters
 ...
 h.release();  // release long-term resources
 


Method Summary
 void
 void
 

Method Detail

public void doCatch(Throwable t) throws Throwable
如果在某个标记内或在以下任何方法:Tag.doStartTag()、Tag.doEndTag()、IterationTag.doAfterBody() 和 BodyTag.doInitBody() 中对正文求值时发生 Throwable,则调用此方法。

如果某个 setter 方法发生 Throwable,则不调用此方法。

此方法可能抛出一个将沿嵌套链进一步向上传播的异常(同一异常或新异常)。如果抛出异常,则将调用 doFinally()。

此方法旨在用于响应异常条件。

t 在此标记中导航的 throwable 异常。
ThrowsThrowable: 如果将沿嵌套链进一步向上重新抛出该异常。

英文文档:

doCatch

void doCatch(Throwable t)
             throws Throwable
Invoked if a Throwable occurs while evaluating the BODY inside a tag or in any of the following methods: Tag.doStartTag(), Tag.doEndTag(), IterationTag.doAfterBody() and BodyTag.doInitBody().

This method is not invoked if the Throwable occurs during one of the setter methods.

This method may throw an exception (the same or a new one) that will be propagated further up the nest chain. If an exception is thrown, doFinally() will be invoked.

This method is intended to be used to respond to an exceptional condition.

Parameters:
t - The throwable exception navigating through this tag.
Throws:
Throwable - if the exception is to be rethrown further up the nest chain.

public void doFinally()
在对任何实现 Tag、IterationTag 或 BodyTag 的类调用 doEndTag() 之后的任何情况下都可调用此方法。即使标记 BODY 中或以下任何方法:Tag.doStartTag()、Tag.doEndTag()、IterationTag.doAfterBody() 和 BodyTag.doInitBody() 中已经发生异常,也可以调用此方法。

如果某个 setter 方法发生 Throwable,则不调用此方法。

此方法不应抛出 Exception。

此方法旨在维护每次调用的数据完整性和资源管理操作。

英文文档:

doFinally

void doFinally()
Invoked in all cases after doEndTag() for any class implementing Tag, IterationTag or BodyTag. This method is invoked even if an exception has occurred in the BODY of the tag, or in any of the following methods: Tag.doStartTag(), Tag.doEndTag(), IterationTag.doAfterBody() and BodyTag.doInitBody().

This method is not invoked if the Throwable occurs during one of the setter methods.

This method should not throw an Exception.

This method is intended to maintain per-invocation data integrity and resource management actions.



Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!