View Javadoc

1   /*
2    * Copyright  2000-2004 The Apache Software Foundation
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License"); 
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License. 
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  }