001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.compiler.classfmt;
011:
012: import java.io.PrintStream;
013: import java.io.PrintWriter;
014:
015: public class ClassFormatException extends Exception {
016:
017: public static final int ErrBadMagic = 1;
018: public static final int ErrBadMinorVersion = 2;
019: public static final int ErrBadMajorVersion = 3;
020: public static final int ErrBadConstantClass = 4;
021: public static final int ErrBadConstantString = 5;
022: public static final int ErrBadConstantNameAndType = 6;
023: public static final int ErrBadConstantFieldRef = 7;
024: public static final int ErrBadConstantMethodRef = 8;
025: public static final int ErrBadConstantInterfaceMethodRef = 9;
026: public static final int ErrBadConstantPoolIndex = 10;
027: public static final int ErrBadSuperclassName = 11;
028: public static final int ErrInterfaceCannotBeFinal = 12;
029: public static final int ErrInterfaceMustBeAbstract = 13;
030: public static final int ErrBadModifiers = 14;
031: public static final int ErrClassCannotBeAbstractFinal = 15;
032: public static final int ErrBadClassname = 16;
033: public static final int ErrBadFieldInfo = 17;
034: public static final int ErrBadMethodInfo = 17;
035: public static final int ErrEmptyConstantPool = 18;
036: public static final int ErrMalformedUtf8 = 19;
037: public static final int ErrUnknownConstantTag = 20;
038: public static final int ErrTruncatedInput = 21;
039: public static final int ErrMethodMustBeAbstract = 22;
040: public static final int ErrMalformedAttribute = 23;
041: public static final int ErrBadInterface = 24;
042: public static final int ErrInterfaceMustSubclassObject = 25;
043: public static final int ErrIncorrectInterfaceMethods = 26;
044: public static final int ErrInvalidMethodName = 27;
045: public static final int ErrInvalidMethodSignature = 28;
046:
047: private static final long serialVersionUID = 6667458511042774540L; // backward compatible
048:
049: private int errorCode;
050: private int bufferPosition;
051: private RuntimeException nestedException;
052: private char[] fileName;
053:
054: public ClassFormatException(RuntimeException e, char[] fileName) {
055: this .nestedException = e;
056: this .fileName = fileName;
057: }
058:
059: public ClassFormatException(int code) {
060: errorCode = code;
061: }
062:
063: public ClassFormatException(int code, int bufPos) {
064: errorCode = code;
065: bufferPosition = bufPos;
066: }
067:
068: /**
069: * @return int
070: */
071: public int getErrorCode() {
072: return errorCode;
073: }
074:
075: /**
076: * @return int
077: */
078: public int getBufferPosition() {
079: return bufferPosition;
080: }
081:
082: /**
083: * Returns the underlying <code>Throwable</code> that caused the failure.
084: *
085: * @return the wrappered <code>Throwable</code>, or <code>null</code>
086: * if the direct case of the failure was at the Java model layer
087: */
088: public Throwable getException() {
089: return this .nestedException;
090: }
091:
092: public void printStackTrace() {
093: printStackTrace(System.err);
094: }
095:
096: /**
097: * Prints this exception's stack trace to the given print stream.
098: *
099: * @param output
100: * the print stream
101: * @since 3.0
102: */
103: public void printStackTrace(PrintStream output) {
104: synchronized (output) {
105: super .printStackTrace(output);
106: Throwable throwable = getException();
107: if (throwable != null) {
108: if (this .fileName != null) {
109: output.print("Caused in "); //$NON-NLS-1$
110: output.print(this .fileName);
111: output.print(" by: "); //$NON-NLS-1$
112: } else {
113: output.print("Caused by: "); //$NON-NLS-1$
114: }
115: throwable.printStackTrace(output);
116: }
117: }
118: }
119:
120: /**
121: * Prints this exception's stack trace to the given print writer.
122: *
123: * @param output
124: * the print writer
125: * @since 3.0
126: */
127: public void printStackTrace(PrintWriter output) {
128: synchronized (output) {
129: super .printStackTrace(output);
130: Throwable throwable = getException();
131: if (throwable != null) {
132: if (this .fileName != null) {
133: output.print("Caused in "); //$NON-NLS-1$
134: output.print(this .fileName);
135: output.print(" by: "); //$NON-NLS-1$
136: } else {
137: output.print("Caused by: "); //$NON-NLS-1$
138: }
139: throwable.printStackTrace(output);
140: }
141: }
142: }
143: }
|