1 2 /* 3 4 The author of this software is Ian Kaplan 5 Bear Products International 6 www.bearcave.com 7 iank@bearcave.com 8 9 Copyright (c) Ian Kaplan, 1999, 2000 10 11 See copyright file for usage and licensing 12 13 */ 14 15 package attr; 16 17 import java.io.*; 18 import util.*; 19 import jconst.*; 20 21 22 /** 23 24 This class represents the exceptions attribute. The structure of 25 this attribute is: 26 27 <pre> 28 Exceptions_attribute { 29 u2 attribute_name_index; 30 u4 attribute_length; 31 u2 number_of_exceptions; 32 u2 exception_index_table[ number_of_exceptions ]; 33 } 34 </pre> 35 36 <p> 37 The attribute_name_index and attribute length are read by the 38 attrFactory.allocAttr method. These values are passed into the class 39 constructor. 40 41 <p> 42 Each non-zero value in the exception_index_table is an index into 43 the constant pool of a constClass_or_String object represent 44 a class type that this method throws. 45 46 <p> 47 JVM Spec. 4.7.5 48 49 <blockquote> 50 The Exceptions attribute indicates which checked exceptions a 51 method may throw. There must be exactly one Exceptions attribute 52 in each method_info structure. 53 </blockquote> 54 55 @author Ian Kaplan 56 */ 57 public class exceptAttr extends attrInfo { 58 constClass_or_String exceptTable[] = null; 59 60 public exceptAttr( String name, int length, 61 DataInputStream dStream, constPool constPoolSec ) { 62 super( name, length ); 63 64 int numExcept = readU2( dStream ); 65 if (numExcept > 0) { 66 constBase obj; 67 int ix; 68 69 exceptTable = new constClass_or_String[ numExcept ]; 70 for (int i = 0; i < numExcept; i++) { 71 // read the index in the constant table for the exception class 72 ix = readU2( dStream ); 73 if (ix > 0) { 74 obj = constPoolSec.constPoolElem( ix ); 75 if (obj != null && obj instanceof constClass_or_String) { 76 exceptTable[i] = (constClass_or_String)obj; 77 } 78 else { 79 errorMessage.errorPrint("exceptAttr: constClass_or_String expected " + 80 "at exception table index " + i ); 81 errorMessage.errorPrint("exceptAttr: obj = " + 82 obj.getClass().getName()); 83 break; // we're in trouble, so get out of the loop 84 } 85 } 86 } // for 87 } 88 } // exceptAttr 89 90 public constClass_or_String[] getExceptTab() { return exceptTable; } 91 92 } // exceptAttr 93