1 /**
2  * This is used to make a table of catch handlers for a method.
3  * @author $Author: jonmeyerny $
4  * @version $Revision: 1.1 $
5  */
6 package jas;
7 
8 import java.io.*;
9 import java.util.*;
10 
11 public class Catchtable
12 {
13   Vector entries;
14 
Catchtable()15   public Catchtable() { entries = new Vector(); }
16 
17   /**
18    * add an entry to the catch table
19    */
20 
addEntry(CatchEntry entry)21   public void addEntry(CatchEntry entry) { entries.addElement(entry); }
22 
23   /**
24    * add an entry to the catch table
25    * @param start Label marking the beginning of the area
26    *       where the catch table is active.
27    * @param end Label marking the end of the area where the
28    *       table is active.
29    * @param handler Label marking the entrypoint into the
30    *  exception handling routine.
31    * @param cat (usually a classCP) informing the VM to direct
32    * any exceptions of this (or its subclasses) to the handler.
33    */
34 
35   public void
addEntry(Label start, Label end, Label handler, CP cat)36   addEntry(Label start, Label end, Label handler, CP cat)
37   { addEntry(new CatchEntry(start, end, handler, cat)); }
38 
39   public void
addEntry(int start, int end, int handler, CP cat)40   addEntry(int start, int end, int handler, CP cat)
41   { addEntry(new CatchEntry(start, end, handler, cat)); }
42 
resolve(ClassEnv e)43   void resolve(ClassEnv e)
44   {
45     for (Enumeration en=entries.elements(); en.hasMoreElements(); )
46       {
47         CatchEntry ce = (CatchEntry)(en.nextElement());
48         ce.resolve(e);
49       }
50   }
51 
size()52   int size()
53   { return (8*entries.size()); } // each entry is 8 bytes
54 
write(ClassEnv e, CodeAttr ce, DataOutputStream out)55   void write(ClassEnv e, CodeAttr ce, DataOutputStream out)
56     throws IOException, jasError
57   {
58     out.writeShort(entries.size());
59     for (Enumeration en = entries.elements(); en.hasMoreElements();)
60       {
61         CatchEntry entry = (CatchEntry)(en.nextElement());
62         entry.write(e, ce, out);
63       }
64   }
65 }
66