    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 */
    017package org.apache.bcel.generic;
    018
    019/**
    020 * Thrown by InstructionList.remove() when one or multiple disposed instructions are still being referenced by an
    021 * InstructionTargeter object. I.e. the InstructionTargeter has to be notified that (one of) the InstructionHandle it is
    022 * referencing is being removed from the InstructionList and thus not valid anymore.
    023 *
    024 * <p>
    025 * Making this an exception instead of a return value forces the user to handle these case explicitly in a try { ... }
    026 * catch. The following code illustrates how this may be done:
    027 * </p>
    028 *
    029 * <PRE>
    030 *     ...
    031 *     try {
    032 *         il.delete(start_ih, end_ih);
    033 *     } catch(TargetLostException e) {
    034 *         for (InstructionHandle target : e.getTargets()) {
    035 *             for (InstructionTargeter targeter : target.getTargeters()) {
    036 *                 targeter.updateTarget(target, new_target);
    037 *             }
    038 *         }
    039 *     }
    040 * </PRE>
    041 *
    042 * @see InstructionHandle
    043 * @see InstructionList
    044 * @see InstructionTargeter
    045 */
    046public final class TargetLostException extends Exception {
    047
    048    private static final long serialVersionUID = -6857272667645328384L;
    049    private final InstructionHandle[] targets;
    050
    051    TargetLostException(final InstructionHandle[] t, final String mesg) {
    052        super(mesg);
    053        targets = t;
    054    }
    055
    056    /**
    057     * @return list of instructions still being targeted.
    058     */
    059    public InstructionHandle[] getTargets() {
    060        return targets;
    061    }
    062}