    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 *  Unless required by applicable law or agreed to in writing, software
    012 *  distributed under the License is distributed on an "AS IS" BASIS,
    013 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 *  See the License for the specific language governing permissions and
    015 *  limitations under the License.
    016 *
    017 */
    018package org.apache.bcel.generic;
    019
    020/**
    021 * Thrown by InstructionList.remove() when one or multiple disposed instructions are still being referenced by an
    022 * InstructionTargeter object. I.e. the InstructionTargeter has to be notified that (one of) the InstructionHandle it is
    023 * referencing is being removed from the InstructionList and thus not valid anymore.
    024 *
    025 * <p>
    026 * Making this an exception instead of a return value forces the user to handle these case explicitely in a try { ... }
    027 * catch. The following code illustrates how this may be done:
    028 * </p>
    029 *
    030 * <PRE>
    031 *     ...
    032 *     try {
    033 *         il.delete(start_ih, end_ih);
    034 *     } catch(TargetLostException e) {
    035 *         for (InstructionHandle target : e.getTargets()) {
    036 *             for (InstructionTargeter targeter : target.getTargeters()) {
    037 *                 targeter.updateTarget(target, new_target);
    038 *             }
    039 *         }
    040 *     }
    041 * </PRE>
    042 *
    043 * @see InstructionHandle
    044 * @see InstructionList
    045 * @see InstructionTargeter
    046 */
    047public final class TargetLostException extends Exception {
    048
    049    private static final long serialVersionUID = -6857272667645328384L;
    050    private final InstructionHandle[] targets;
    051
    052    TargetLostException(final InstructionHandle[] t, final String mesg) {
    053        super(mesg);
    054        targets = t;
    055    }
    056
    057    /**
    058     * @return list of instructions still being targeted.
    059     */
    060    public InstructionHandle[] getTargets() {
    061        return targets;
    062    }
    063}