1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.bcel.generic;
18
19 /***
20 * Thrown by InstructionList.remove() when one or multiple disposed instruction
21 * are still being referenced by a InstructionTargeter object. I.e. the
22 * InstructionTargeter has to be notified that (one of) the InstructionHandle it
23 * is referencing is being removed from the InstructionList and thus not valid anymore.
24 *
25 * Making this an exception instead of a return value forces the user to handle
26 * these case explicitely in a try { ... } catch. The following code illustrates
27 * how this may be done:
28 *
29 * <PRE>
30 * ...
31 * try {
32 * il.delete(start_ih, end_ih);
33 * } catch(TargetLostException e) {
34 * InstructionHandle[] targets = e.getTargets();
35 * for(int i=0; i < targets.length; i++) {
36 * InstructionTargeter[] targeters = targets[i].getTargeters();
37 *
38 * for(int j=0; j < targeters.length; j++)
39 * targeters[j].updateTarget(targets[i], new_target);
40 * }
41 * }
42 * </PRE>
43 *
44 * @see InstructionHandle
45 * @see InstructionList
46 * @see InstructionTargeter
47 * @version $Id: TargetLostException.java 386056 2006-03-15 11:31:56Z tcurdt $
48 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
49 */
50 public final class TargetLostException extends Exception {
51
52 private InstructionHandle[] targets;
53
54
55 TargetLostException(InstructionHandle[] t, String mesg) {
56 super(mesg);
57 targets = t;
58 }
59
60
61 /***
62 * @return list of instructions still being targeted.
63 */
64 public InstructionHandle[] getTargets() {
65 return targets;
66 }
67 }