1 17 package org.apache.bcel.classfile; 18 19 import java.io.DataInputStream ; 20 import java.io.DataOutputStream ; 21 import java.io.IOException ; 22 import java.io.Serializable ; 23 import org.apache.bcel.Constants; 24 25 34 public final class CodeException implements Cloneable , Constants, Node, Serializable { 35 36 private int start_pc; private int end_pc; private int handler_pc; 41 private int catch_type; 45 46 47 50 public CodeException(CodeException c) { 51 this(c.getStartPC(), c.getEndPC(), c.getHandlerPC(), c.getCatchType()); 52 } 53 54 55 60 CodeException(DataInputStream file) throws IOException { 61 this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), file 62 .readUnsignedShort()); 63 } 64 65 66 76 public CodeException(int start_pc, int end_pc, int handler_pc, int catch_type) { 77 this.start_pc = start_pc; 78 this.end_pc = end_pc; 79 this.handler_pc = handler_pc; 80 this.catch_type = catch_type; 81 } 82 83 84 91 public void accept( Visitor v ) { 92 v.visitCodeException(this); 93 } 94 95 96 102 public final void dump( DataOutputStream file ) throws IOException { 103 file.writeShort(start_pc); 104 file.writeShort(end_pc); 105 file.writeShort(handler_pc); 106 file.writeShort(catch_type); 107 } 108 109 110 114 public final int getCatchType() { 115 return catch_type; 116 } 117 118 119 122 public final int getEndPC() { 123 return end_pc; 124 } 125 126 127 130 public final int getHandlerPC() { 131 return handler_pc; 132 } 133 134 135 138 public final int getStartPC() { 139 return start_pc; 140 } 141 142 143 146 public final void setCatchType( int catch_type ) { 147 this.catch_type = catch_type; 148 } 149 150 151 154 public final void setEndPC( int end_pc ) { 155 this.end_pc = end_pc; 156 } 157 158 159 162 public final void setHandlerPC( int handler_pc ) { 163 this.handler_pc = handler_pc; 164 } 165 166 167 170 public final void setStartPC( int start_pc ) { 171 this.start_pc = start_pc; 172 } 173 174 175 178 public final String toString() { 179 return "CodeException(start_pc = " + start_pc + ", end_pc = " + end_pc + ", handler_pc = " 180 + handler_pc + ", catch_type = " + catch_type + ")"; 181 } 182 183 184 187 public final String toString( ConstantPool cp, boolean verbose ) { 188 String str; 189 if (catch_type == 0) { 190 str = "<Any exception>(0)"; 191 } else { 192 str = Utility.compactClassName(cp.getConstantString(catch_type, CONSTANT_Class), false) 193 + (verbose ? "(" + catch_type + ")" : ""); 194 } 195 return start_pc + "\t" + end_pc + "\t" + handler_pc + "\t" + str; 196 } 197 198 199 public final String toString( ConstantPool cp ) { 200 return toString(cp, true); 201 } 202 203 204 207 public CodeException copy() { 208 try { 209 return (CodeException) clone(); 210 } catch (CloneNotSupportedException e) { 211 } 212 return null; 213 } 214 } 215 | Popular Tags |