KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > types > reflect > Exceptions


1 package polyglot.types.reflect;
2
3 import java.util.*;
4 import java.io.*;
5
6 /**
7  * Exceptions describes the types of exceptions that a method may throw.
8  * The Exceptions attribute stores a list of indices into the constant
9  * pool of the types of exceptions thrown by the method.
10  *
11  * @see polyglot.types.reflect Method
12  *
13  * @author Nate Nystrom
14  * (<a HREF="mailto:nystrom@cs.purdue.edu">nystrom@cs.purdue.edu</a>)
15  */

16 class Exceptions extends Attribute {
17   int[] exceptions;
18   ClassFile clazz;
19
20   /**
21    * Constructor for create an <code>Exceptions</code> from scratch.
22    *
23    * @param nameIndex
24    * The index of the UTF8 string "Exceptions" in the class's
25    * constant pool
26    * @param exceptions
27    * A non-<code>null</code> array of indices into the constant
28    * pool for the types of the exceptions
29    */

30   Exceptions(ClassFile clazz, int nameIndex, int[] exceptions) {
31     super(nameIndex, (2 * exceptions.length) + 2);
32     this.clazz = clazz;
33     this.exceptions = exceptions;
34   }
35
36   /**
37    * Constructor. Create an Exceptions attribute from a data stream.
38    *
39    * @param in
40    * The data stream of the class file.
41    * @param nameIndex
42    * The index into the constant pool of the name of the attribute.
43    * @param length
44    * The length of the attribute, excluding the header.
45    * @exception IOException
46    * If an error occurs while reading.
47    */

48   Exceptions(ClassFile clazz, DataInputStream in,
49             int nameIndex, int length) throws IOException
50   {
51     super(nameIndex, length);
52
53     this.clazz = clazz;
54
55     int count = in.readUnsignedShort();
56
57     exceptions = new int[count];
58
59     for (int i = 0; i < count; i++) {
60       exceptions[i] = in.readUnsignedShort();
61     }
62   }
63 }
64
Popular Tags