3 import java.io.IOException;
5 import js.tinyvm.io.IByteWriter;
6 import js.tinyvm.io.IOUtilities;
8 import org.apache.bcel.classfile.CodeException;
9 import org.apache.bcel.classfile.ConstantClass;
10 import org.apache.bcel.classfile.JavaClass;
12 public class ExceptionRecord implements WritableData
17 public ExceptionRecord (CodeException aExcep, Binary aBinary, JavaClass aCF)
21 int pCPIndex = aExcep.getCatchType();
24 // An index of 0 means ANY.
25 iClassIndex = aBinary.getClassIndex("java/lang/Throwable");
29 ConstantClass pCls = (ConstantClass) aCF.getConstantPool()
30 .getConstant(pCPIndex);
31 String pName = pCls.getBytes(aCF.getConstantPool());
32 iClassIndex = aBinary.getClassIndex(pName);
34 if (iClassIndex == -1)
36 throw new TinyVMException("Exception not found: " + iExcep);
40 public int getLength ()
42 return IOUtilities.adjustedSize(2 + // start
49 public void dump (IByteWriter aOut) throws TinyVMException
51 int pStart = iExcep.getStartPC();
52 int pEnd = iExcep.getEndPC();
53 int pHandler = iExcep.getHandlerPC();
54 if (pStart > TinyVMConstants.MAX_CODE || pEnd > TinyVMConstants.MAX_CODE
55 || pHandler > TinyVMConstants.MAX_CODE)
57 throw new TinyVMException("Exception handler with huge PCs");
64 aOut.writeU2(pHandler);
65 aOut.writeU1(iClassIndex);
66 IOUtilities.writePadding(aOut, 2);
70 throw new TinyVMException(e.getMessage(), e);
74 public boolean equals (Object aOther)
76 if (!(aOther instanceof ExceptionRecord))
78 return ((ExceptionRecord) aOther).iExcep.equals(iExcep);
81 public int hashCode ()
83 return iExcep.hashCode();