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 */
047public final class TargetLostException extends Exception {
048
049    private static final long serialVersionUID = -6857272667645328384L;
050    private final InstructionHandle[] targets;
051
052
053    TargetLostException(final InstructionHandle[] t, final String mesg) {
054        super(mesg);
055        targets = t;
056    }
057
058
059    /**
060     * @return list of instructions still being targeted.
061     */
062    public InstructionHandle[] getTargets() {
063        return targets;
064    }
065}