    001// Copyright 2011 The Apache Software Foundation
    002//
    003// Licensed under the Apache License, Version 2.0 (the "License");
    004// you may not use this file except in compliance with the License.
    005// You may obtain a copy of the License at
    006//
    007// http://www.apache.org/licenses/LICENSE-2.0
    008//
    009// Unless required by applicable law or agreed to in writing, software
    010// distributed under the License is distributed on an "AS IS" BASIS,
    011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    012// See the License for the specific language governing permissions and
    013// limitations under the License.
    014
    015package org.apache.tapestry5.plastic;
    016
    017/**
    018 * Allows a portion of a method to be marked so that exception and finally handlers can be provided.
    019 *
    020 * @see InstructionBuilder#startTryCatch(TryCatchCallback)
    021 */
    022public interface TryCatchBlock
    023{
    024    /**
    025     * Invoked first, to generate the code in which exceptions may be caught.
    026     */
    027    void addTry(InstructionBuilderCallback callback);
    028
    029    /**
    030     * Ends the block (if not already ended) and inserts a catch block for the named exception.
    031     * The InstructionBuilder is returned so that the code for handling the exception can be added. The exception object
    032     * will be on top of the stack. This should be called after {@link #addTry(InstructionBuilderCallback)}.
    033     * <p>
    034     * Note: no attempt is made currently to sort the handlers; for example adding a catch for java.lang.Exception first
    035     * will mean that more specific exception handlers added later will never be invoked.
    036     *
    037     * @param exceptionClassName
    038     *            caught exception class
    039     * @param callback
    040     *            that implements the logic of the catch block
    041     */
    042    @Opcodes("TRYCATCHBLOCK")
    043    void addCatch(String exceptionClassName, InstructionBuilderCallback callback);
    044
    045    /**
    046     * As with {@link #addCatch(String, InstructionBuilderCallback)}, but the exception caught is
    047     * null, which acts as a finally block in the Java language. This must be called last (after
    048     * {@link #addTry(InstructionBuilderCallback)} and any calls to
    049     * {@link #addCatch(String, InstructionBuilderCallback)}.
    050     *
    051     * @param callback
    052     *            implements the logic of the finally block
    053     */
    054    @Opcodes("TRYCATCHBLOCK")
    055    void addFinally(InstructionBuilderCallback callback);
    056}