KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > classfile > ExceptionTableEntry


1 /*
2  * ExceptionTableEntry.java
3  *
4  * The contents of this file are subject to the terms of the Common Development
5  * and Distribution License (the License). You may not use this file except in
6  * compliance with the License.
7  *
8  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
9  * or http://www.netbeans.org/cddl.txt.
10  *
11  * When distributing Covered Code, include this CDDL Header Notice in each file
12  * and include the License file at http://www.netbeans.org/cddl.txt.
13  * If applicable, add the following below the CDDL Header, with the fields
14  * enclosed by brackets [] replaced by your own identifying information:
15  * "Portions Copyrighted [year] [name of copyright owner]"
16  *
17  * The Original Software is NetBeans. The Initial Developer of the Original
18  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
19  * Microsystems, Inc. All Rights Reserved.
20  *
21  * Contributor(s): Thomas Ball
22  *
23  * Version: $Revision: 1.6 $
24  */

25
26 package org.netbeans.modules.classfile;
27
28 import java.io.DataInputStream JavaDoc;
29 import java.io.IOException JavaDoc;
30
31 /**
32  * An entry in the exception table of a method's code attribute.
33  *
34  * @author Thomas Ball
35  */

36 public final class ExceptionTableEntry {
37
38     int startPC;
39     int endPC;
40     int handlerPC;
41     CPClassInfo catchType; // may be null for "finally" exception handler
42

43     static ExceptionTableEntry[] loadExceptionTable(DataInputStream JavaDoc in, ConstantPool pool)
44       throws IOException JavaDoc {
45         int n = in.readUnsignedShort();
46         ExceptionTableEntry[] exceptions = new ExceptionTableEntry[n];
47         for (int i = 0; i < n; i++)
48             exceptions[i] = new ExceptionTableEntry(in, pool);
49         return exceptions;
50     }
51
52     /** Creates new ExceptionTableEntry */
53     ExceptionTableEntry(DataInputStream JavaDoc in, ConstantPool pool)
54       throws IOException JavaDoc {
55         loadExceptionEntry(in, pool);
56     }
57
58     private void loadExceptionEntry(DataInputStream JavaDoc in, ConstantPool pool)
59       throws IOException JavaDoc {
60         startPC = in.readUnsignedShort();
61         endPC = in.readUnsignedShort();
62         handlerPC = in.readUnsignedShort();
63         int typeIndex = in.readUnsignedShort();
64         if (typeIndex != 0) // may be 0 for "finally" exception handler
65
try {
66             catchType = pool.getClass(typeIndex);
67         } catch (IndexOutOfBoundsException JavaDoc e) {
68             throw new InvalidClassFileAttributeException(
69                     "invalid catchType (" + typeIndex + ") in exception table entry", e);
70         }
71     }
72     
73     /**
74      * Returns the beginning offset into the method's bytecodes of this
75      * exception handler.
76      */

77     public final int getStartPC() {
78         return startPC;
79     }
80     
81     /**
82      * Returns the ending offset into the method's bytecodes of this
83      * exception handler, or the length of the bytecode array if the
84      * handler supports the method's last bytecodes (JVM 4.7.3).
85      */

86     public final int getEndPC() {
87         return endPC;
88     }
89     
90     /**
91      * Returns the starting offset into the method's bytecodes of the
92      * exception handling code.
93      */

94     public final int getHandlerPC() {
95         return handlerPC;
96     }
97     
98     /**
99      * Returns the type of exception handler, or <code>null</code>
100      * if this handler catches all exceptions, such as an exception
101      * handler for a "<code>finally</code>" clause (JVM 4.7.3).
102      */

103     public final CPClassInfo getCatchType() {
104         return catchType;
105     }
106 }
107
Popular Tags