1 /*******************************************************************************
2  * Copyright (c) 2000, 2009 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.jdt.internal.core.util;
15 
16 import org.eclipse.jdt.core.util.ClassFormatException;
17 import org.eclipse.jdt.core.util.IConstantPool;
18 import org.eclipse.jdt.core.util.IConstantPoolConstant;
19 import org.eclipse.jdt.core.util.IConstantPoolEntry;
20 import org.eclipse.jdt.core.util.IExceptionTableEntry;
21 
22 /**
23  * This class describes an entry in the exception table attribute according
24  * to the JVM specifications.
25  */
26 public class ExceptionTableEntry
27 	extends ClassFileStruct
28 	implements IExceptionTableEntry {
29 
30 	private int startPC;
31 	private int endPC;
32 	private int handlerPC;
33 	private int catchTypeIndex;
34 	private char[] catchType;
35 
ExceptionTableEntry(byte[] classFileBytes, IConstantPool constantPool, int offset)36 	ExceptionTableEntry(byte[] classFileBytes, IConstantPool constantPool, int offset) throws ClassFormatException {
37 		this.startPC = u2At(classFileBytes, 0, offset);
38 		this.endPC = u2At(classFileBytes, 2, offset);
39 		this.handlerPC = u2At(classFileBytes, 4, offset);
40 		this.catchTypeIndex = u2At(classFileBytes, 6, offset);
41 		if (this.catchTypeIndex != 0) {
42 			IConstantPoolEntry constantPoolEntry = constantPool.decodeEntry(this.catchTypeIndex);
43 			if (constantPoolEntry.getKind() != IConstantPoolConstant.CONSTANT_Class) {
44 				throw new ClassFormatException(ClassFormatException.INVALID_CONSTANT_POOL_ENTRY);
45 			}
46 			this.catchType = constantPoolEntry.getClassInfoName();
47 		}
48 	}
49 	/**
50 	 * @see IExceptionTableEntry#getStartPC()
51 	 */
52 	@Override
getStartPC()53 	public int getStartPC() {
54 		return this.startPC;
55 	}
56 
57 	/**
58 	 * @see IExceptionTableEntry#getEndPC()
59 	 */
60 	@Override
getEndPC()61 	public int getEndPC() {
62 		return this.endPC;
63 	}
64 
65 	/**
66 	 * @see IExceptionTableEntry#getHandlerPC()
67 	 */
68 	@Override
getHandlerPC()69 	public int getHandlerPC() {
70 		return this.handlerPC;
71 	}
72 
73 	/**
74 	 * @see IExceptionTableEntry#getCatchTypeIndex()
75 	 */
76 	@Override
getCatchTypeIndex()77 	public int getCatchTypeIndex() {
78 		return this.catchTypeIndex;
79 	}
80 
81 	/**
82 	 * @see IExceptionTableEntry#getCatchType()
83 	 */
84 	@Override
getCatchType()85 	public char[] getCatchType() {
86 		return this.catchType;
87 	}
88 
89 }
90