1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 package org.apache.bcel.generic; 19 20 /** 21 * Thrown by InstructionList.remove() when one or multiple disposed instructions 22 * are still being referenced by an InstructionTargeter object. I.e. the 23 * InstructionTargeter has to be notified that (one of) the InstructionHandle it 24 * is referencing is being removed from the InstructionList and thus not valid anymore. 25 * 26 * <p>Making this an exception instead of a return value forces the user to handle 27 * these case explicitely in a try { ... } catch. The following code illustrates 28 * how this may be done:</p> 29 * 30 * <PRE> 31 * ... 32 * try { 33 * il.delete(start_ih, end_ih); 34 * } catch(TargetLostException e) { 35 * for (InstructionHandle target : e.getTargets()) { 36 * for (InstructionTargeter targeter : target.getTargeters()) { 37 * targeter.updateTarget(target, new_target); 38 * } 39 * } 40 * } 41 * </PRE> 42 * 43 * @see InstructionHandle 44 * @see InstructionList 45 * @see InstructionTargeter 46 * @version $Id$ 47 */ 48 public final class TargetLostException extends Exception { 49 50 private static final long serialVersionUID = -6857272667645328384L; 51 private final InstructionHandle[] targets; 52 53 TargetLostException(final InstructionHandle[] t, final String mesg)54 TargetLostException(final InstructionHandle[] t, final String mesg) { 55 super(mesg); 56 targets = t; 57 } 58 59 60 /** 61 * @return list of instructions still being targeted. 62 */ getTargets()63 public InstructionHandle[] getTargets() { 64 return targets; 65 } 66 } 67