1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others. All rights reserved.
3 * This program and the accompanying materials are made available under the
4 * terms of the Common Public License v1.0 which accompanies this distribution,
5 * and is available at http://www.eclipse.org/legal/cpl-v10.html
7 * Contributors: IBM Corporation - initial API and implementation
8 ******************************************************************************/
9 package org.eclipse.jdt.internal.compiler.classfmt;
10 import java.io.PrintStream;
11 import java.io.PrintWriter;
12 public class ClassFormatException extends Exception {
13 public static final int ErrBadMagic = 1;
14 public static final int ErrBadMinorVersion = 2;
15 public static final int ErrBadMajorVersion = 3;
16 public static final int ErrBadConstantClass = 4;
17 public static final int ErrBadConstantString = 5;
18 public static final int ErrBadConstantNameAndType = 6;
19 public static final int ErrBadConstantFieldRef = 7;
20 public static final int ErrBadConstantMethodRef = 8;
21 public static final int ErrBadConstantInterfaceMethodRef = 9;
22 public static final int ErrBadConstantPoolIndex = 10;
23 public static final int ErrBadSuperclassName = 11;
24 public static final int ErrInterfaceCannotBeFinal = 12;
25 public static final int ErrInterfaceMustBeAbstract = 13;
26 public static final int ErrBadModifiers = 14;
27 public static final int ErrClassCannotBeAbstractFinal = 15;
28 public static final int ErrBadClassname = 16;
29 public static final int ErrBadFieldInfo = 17;
30 public static final int ErrBadMethodInfo = 17;
31 public static final int ErrEmptyConstantPool = 18;
32 public static final int ErrMalformedUtf8 = 19;
33 public static final int ErrUnknownConstantTag = 20;
34 public static final int ErrTruncatedInput = 21;
35 public static final int ErrMethodMustBeAbstract = 22;
36 public static final int ErrMalformedAttribute = 23;
37 public static final int ErrBadInterface = 24;
38 public static final int ErrInterfaceMustSubclassObject = 25;
39 public static final int ErrIncorrectInterfaceMethods = 26;
40 public static final int ErrInvalidMethodName = 27;
41 public static final int ErrInvalidMethodSignature = 28;
43 private static final long serialVersionUID = 6667458511042774540L; // backward compatible
45 private int errorCode;
46 private int bufferPosition;
47 private RuntimeException nestedException;
48 private char[] fileName;
50 public ClassFormatException(RuntimeException e, char[] fileName) {
51 this.nestedException = e;
53 public ClassFormatException(int code) {
56 public ClassFormatException(int code, int bufPos) {
58 bufferPosition = bufPos;
63 public int getErrorCode() {
69 public int getBufferPosition() {
70 return bufferPosition;
73 * Returns the underlying <code>Throwable</code> that caused the failure.
75 * @return the wrappered <code>Throwable</code>, or <code>null</code>
76 * if the direct case of the failure was at the Java model layer
78 public Throwable getException() {
79 return this.nestedException;
81 public void printStackTrace() {
82 printStackTrace(System.err);
85 * Prints this exception's stack trace to the given print stream.
91 public void printStackTrace(PrintStream output) {
92 synchronized (output) {
93 super.printStackTrace(output);
94 Throwable throwable = getException();
95 if (throwable != null) {
96 if (this.fileName != null) {
97 output.print("Caused in "); //$NON-NLS-1$
98 output.print(this.fileName);
99 output.print(" by: "); //$NON-NLS-1$
101 output.print("Caused by: "); //$NON-NLS-1$
103 throwable.printStackTrace(output);
108 * Prints this exception's stack trace to the given print writer.
114 public void printStackTrace(PrintWriter output) {
115 synchronized (output) {
116 super.printStackTrace(output);
117 Throwable throwable = getException();
118 if (throwable != null) {
119 if (this.fileName != null) {
120 output.print("Caused in "); //$NON-NLS-1$
121 output.print(this.fileName);
122 output.print(" by: "); //$NON-NLS-1$
124 output.print("Caused by: "); //$NON-NLS-1$
126 throwable.printStackTrace(output);