Skip to content

Package: TryCatchFinally

TryCatchFinally

Coverage

1: /*
2: * Copyright (c) 1997, 2020 Oracle and/or its affiliates and others.
3: * All rights reserved.
4: * Copyright 2004 The Apache Software Foundation
5: *
6: * Licensed under the Apache License, Version 2.0 (the "License");
7: * you may not use this file except in compliance with the License.
8: * You may obtain a copy of the License at
9: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: package jakarta.servlet.jsp.tagext;
20:
21: /**
22: * The auxiliary interface of a Tag, IterationTag or BodyTag tag handler that wants additional hooks for managing
23: * resources.
24: *
25: * <p>
26: * This interface provides two new methods: doCatch(Throwable) and doFinally(). The prototypical invocation is as
27: * follows:
28: *
29: * <pre>
30: * h = get a Tag(); // get a tag handler, perhaps from pool
31: *
32: * h.setPageContext(pc); // initialize as desired
33: * h.setParent(null);
34: * h.setFoo("foo");
35: *
36: * // tag invocation protocol; see Tag.java
37: * try {
38: * doStartTag()...
39: * ....
40: * doEndTag()...
41: * } catch (Throwable t) {
42: * // react to exceptional condition
43: * h.doCatch(t);
44: * } finally {
45: * // restore data invariants and release per-invocation resources
46: * h.doFinally();
47: * }
48: *
49: * ... other invocations perhaps with some new setters
50: * ...
51: * h.release(); // release long-term resources
52: * </pre>
53: */
54: public interface TryCatchFinally {
55:
56: /**
57: * Invoked if a Throwable occurs while evaluating the BODY inside a tag or in any of the following methods:
58: * Tag.doStartTag(), Tag.doEndTag(), IterationTag.doAfterBody() and BodyTag.doInitBody().
59: *
60: * <p>
61: * This method is not invoked if the Throwable occurs during one of the setter methods.
62: *
63: * <p>
64: * This method may throw an exception (the same or a new one) that will be propagated further up the nest chain. If
65: * an exception is thrown, doFinally() will be invoked.
66: *
67: * <p>
68: * This method is intended to be used to respond to an exceptional condition.
69: *
70: * @param t The throwable exception navigating through this tag.
71: * @throws Throwable if the exception is to be rethrown further up the nest chain.
72: */
73: void doCatch(Throwable t) throws Throwable;
74:
75: /**
76: * Invoked in all cases after doEndTag() for any class implementing Tag, IterationTag or BodyTag. This method is
77: * invoked even if an exception has occurred in the BODY of the tag, or in any of the following methods:
78: * Tag.doStartTag(), Tag.doEndTag(), IterationTag.doAfterBody() and BodyTag.doInitBody().
79: *
80: * <p>
81: * This method is not invoked if the Throwable occurs during one of the setter methods.
82: *
83: * <p>
84: * This method should not throw an Exception.
85: *
86: * <p>
87: * This method is intended to maintain per-invocation data integrity and resource management actions.
88: */
89: void doFinally();
90: }