KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jas > Catchtable


1 /**
2  * This is used to make a table of catch handlers for a method.
3  * @author $Author: fqian $
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
15   public Catchtable() { entries = new Vector(); }
16
17   /**
18    * add an entry to the catch table
19    */

20
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
36   addEntry(Label start, Label end, Label handler, CP cat)
37   { addEntry(new CatchEntry(start, end, handler, cat)); }
38
39   void resolve(ClassEnv e)
40   {
41     for (Enumeration en=entries.elements(); en.hasMoreElements(); )
42       {
43         CatchEntry ce = (CatchEntry)(en.nextElement());
44         ce.resolve(e);
45       }
46   }
47
48   int size()
49   { return (8*entries.size()); } // each entry is 8 bytes
50

51   void write(ClassEnv e, CodeAttr ce, DataOutputStream out)
52     throws IOException, jasError
53   {
54     out.writeShort(entries.size());
55     for (Enumeration en = entries.elements(); en.hasMoreElements();)
56       {
57         CatchEntry entry = (CatchEntry)(en.nextElement());
58         entry.write(e, ce, out);
59       }
60   }
61 }
62
Popular Tags