    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
    022 * are still being referenced by an InstructionTargeter object. I.e. the
    023 * InstructionTargeter has to be notified that (one of) the InstructionHandle it
    024 * is referencing is being removed from the InstructionList and thus not valid anymore.
    025 *
    026 * <p>Making this an exception instead of a return value forces the user to handle
    027 * these case explicitely in a try { ... } catch. The following code illustrates
    028 * how this may be done:</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 * @version $Id$
    047 */
    048public final class TargetLostException extends Exception {
    049
    050    private static final long serialVersionUID = -6857272667645328384L;
    051    private final InstructionHandle[] targets;
    052
    053
    054    TargetLostException(final InstructionHandle[] t, final String mesg) {
    055        super(mesg);
    056        targets = t;
    057    }
    058
    059
    060    /**
    061     * @return list of instructions still being targeted.
    062     */
    063    public InstructionHandle[] getTargets() {
    064        return targets;
    065    }
    066}