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 package org.apache.bcel.generic; 18 19 /** 20 * Thrown by InstructionList.remove() when one or multiple disposed instructions are still being referenced by an 21 * InstructionTargeter object. I.e. the InstructionTargeter has to be notified that (one of) the InstructionHandle it is 22 * referencing is being removed from the InstructionList and thus not valid anymore. 23 * 24 * <p> 25 * Making this an exception instead of a return value forces the user to handle these case explicitly in a try { ... } 26 * catch. The following code illustrates how this may be done: 27 * </p> 28 * 29 * <PRE> 30 * ... 31 * try { 32 * il.delete(start_ih, end_ih); 33 * } catch (TargetLostException e) { 34 * for (InstructionHandle target : e.getTargets()) { 35 * for (InstructionTargeter targeter : target.getTargeters()) { 36 * targeter.updateTarget(target, new_target); 37 * } 38 * } 39 * } 40 * </PRE> 41 * 42 * @see InstructionHandle 43 * @see InstructionList 44 * @see InstructionTargeter 45 */ 46 public final class TargetLostException extends Exception { 47 48 private static final long serialVersionUID = -6857272667645328384L; 49 private final InstructionHandle[] targets; 50 51 TargetLostException(final InstructionHandle[] t, final String mesg) { 52 super(mesg); 53 targets = t; 54 } 55 56 /** 57 * @return list of instructions still being targeted. 58 */ 59 public InstructionHandle[] getTargets() { 60 return targets; 61 } 62 }