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 {
14 public static final int ErrBadMagic = 1;
15 public static final int ErrBadMinorVersion = 2;
16 public static final int ErrBadMajorVersion = 3;
17 public static final int ErrBadConstantClass = 4;
18 public static final int ErrBadConstantString = 5;
19 public static final int ErrBadConstantNameAndType = 6;
20 public static final int ErrBadConstantFieldRef = 7;
21 public static final int ErrBadConstantMethodRef = 8;
22 public static final int ErrBadConstantInterfaceMethodRef = 9;
23 public static final int ErrBadConstantPoolIndex = 10;
24 public static final int ErrBadSuperclassName = 11;
25 public static final int ErrInterfaceCannotBeFinal = 12;
26 public static final int ErrInterfaceMustBeAbstract = 13;
27 public static final int ErrBadModifiers = 14;
28 public static final int ErrClassCannotBeAbstractFinal = 15;
29 public static final int ErrBadClassname = 16;
30 public static final int ErrBadFieldInfo = 17;
31 public static final int ErrBadMethodInfo = 17;
32 public static final int ErrEmptyConstantPool = 18;
33 public static final int ErrMalformedUtf8 = 19;
34 public static final int ErrUnknownConstantTag = 20;
35 public static final int ErrTruncatedInput = 21;
36 public static final int ErrMethodMustBeAbstract = 22;
37 public static final int ErrMalformedAttribute = 23;
38 public static final int ErrBadInterface = 24;
39 public static final int ErrInterfaceMustSubclassObject = 25;
40 public static final int ErrIncorrectInterfaceMethods = 26;
41 public static final int ErrInvalidMethodName = 27;
42 public static final int ErrInvalidMethodSignature = 28;
44 private static final long serialVersionUID = 6667458511042774540L; // backward compatible
46 private int errorCode;
47 private int bufferPosition;
48 private RuntimeException nestedException;
49 private char[] fileName;
51 public ClassFormatException(RuntimeException e, char[] fileName) {
52 this.nestedException = e;
54 public ClassFormatException(int code) {
57 public ClassFormatException(int code, int bufPos) {
59 bufferPosition = bufPos;
64 public int getErrorCode() {
70 public int getBufferPosition() {
71 return bufferPosition;
74 * Returns the underlying <code>Throwable</code> that caused the failure.
76 * @return the wrappered <code>Throwable</code>, or <code>null</code>
77 * if the direct case of the failure was at the Java model layer
79 public Throwable getException() {
80 return this.nestedException;
82 public void printStackTrace() {
83 printStackTrace(System.err);
86 * Prints this exception's stack trace to the given print stream.
92 public void printStackTrace(PrintStream output) {
93 synchronized (output) {
94 super.printStackTrace(output);
95 Throwable throwable = getException();
96 if (throwable != null) {
97 if (this.fileName != null) {
98 output.print("Caused in "); //$NON-NLS-1$
99 output.print(this.fileName);
100 output.print(" by: "); //$NON-NLS-1$
102 output.print("Caused by: "); //$NON-NLS-1$
104 throwable.printStackTrace(output);
109 * Prints this exception's stack trace to the given print writer.
115 public void printStackTrace(PrintWriter output) {
116 synchronized (output) {
117 super.printStackTrace(output);
118 Throwable throwable = getException();
119 if (throwable != null) {
120 if (this.fileName != null) {
121 output.print("Caused in "); //$NON-NLS-1$
122 output.print(this.fileName);
123 output.print(" by: "); //$NON-NLS-1$
125 output.print("Caused by: "); //$NON-NLS-1$
127 throwable.printStackTrace(output);