KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > classfmt > ClassFormatException


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.compiler.classfmt;
12 import java.io.PrintStream JavaDoc;
13 import java.io.PrintWriter JavaDoc;
14 public class ClassFormatException extends Exception JavaDoc {
15     
16     public static final int ErrBadMagic = 1;
17     public static final int ErrBadMinorVersion = 2;
18     public static final int ErrBadMajorVersion = 3;
19     public static final int ErrBadConstantClass = 4;
20     public static final int ErrBadConstantString = 5;
21     public static final int ErrBadConstantNameAndType = 6;
22     public static final int ErrBadConstantFieldRef = 7;
23     public static final int ErrBadConstantMethodRef = 8;
24     public static final int ErrBadConstantInterfaceMethodRef = 9;
25     public static final int ErrBadConstantPoolIndex = 10;
26     public static final int ErrBadSuperclassName = 11;
27     public static final int ErrInterfaceCannotBeFinal = 12;
28     public static final int ErrInterfaceMustBeAbstract = 13;
29     public static final int ErrBadModifiers = 14;
30     public static final int ErrClassCannotBeAbstractFinal = 15;
31     public static final int ErrBadClassname = 16;
32     public static final int ErrBadFieldInfo = 17;
33     public static final int ErrBadMethodInfo = 17;
34     public static final int ErrEmptyConstantPool = 18;
35     public static final int ErrMalformedUtf8 = 19;
36     public static final int ErrUnknownConstantTag = 20;
37     public static final int ErrTruncatedInput = 21;
38     public static final int ErrMethodMustBeAbstract = 22;
39     public static final int ErrMalformedAttribute = 23;
40     public static final int ErrBadInterface = 24;
41     public static final int ErrInterfaceMustSubclassObject = 25;
42     public static final int ErrIncorrectInterfaceMethods = 26;
43     public static final int ErrInvalidMethodName = 27;
44     public static final int ErrInvalidMethodSignature = 28;
45
46     private static final long serialVersionUID = 6667458511042774540L; // backward compatible
47

48     private int errorCode;
49     private int bufferPosition;
50     private RuntimeException JavaDoc nestedException;
51     private char[] fileName;
52
53     public ClassFormatException(RuntimeException JavaDoc e, char[] fileName) {
54         this.nestedException = e;
55         this.fileName = fileName;
56     }
57     public ClassFormatException(int code) {
58         errorCode = code;
59     }
60     public ClassFormatException(int code, int bufPos) {
61         errorCode = code;
62         bufferPosition = bufPos;
63     }
64     /**
65      * @return int
66      */

67     public int getErrorCode() {
68         return errorCode;
69     }
70     /**
71      * @return int
72      */

73     public int getBufferPosition() {
74         return bufferPosition;
75     }
76     /**
77      * Returns the underlying <code>Throwable</code> that caused the failure.
78      *
79      * @return the wrappered <code>Throwable</code>, or <code>null</code>
80      * if the direct case of the failure was at the Java model layer
81      */

82     public Throwable JavaDoc getException() {
83         return this.nestedException;
84     }
85     public void printStackTrace() {
86         printStackTrace(System.err);
87     }
88     /**
89      * Prints this exception's stack trace to the given print stream.
90      *
91      * @param output
92      * the print stream
93      * @since 3.0
94      */

95     public void printStackTrace(PrintStream JavaDoc output) {
96         synchronized (output) {
97             super.printStackTrace(output);
98             Throwable JavaDoc throwable = getException();
99             if (throwable != null) {
100                 if (this.fileName != null) {
101                     output.print("Caused in "); //$NON-NLS-1$
102
output.print(this.fileName);
103                     output.print(" by: "); //$NON-NLS-1$
104
} else {
105                     output.print("Caused by: "); //$NON-NLS-1$
106
}
107                 throwable.printStackTrace(output);
108             }
109         }
110     }
111     /**
112      * Prints this exception's stack trace to the given print writer.
113      *
114      * @param output
115      * the print writer
116      * @since 3.0
117      */

118     public void printStackTrace(PrintWriter JavaDoc output) {
119         synchronized (output) {
120             super.printStackTrace(output);
121             Throwable JavaDoc throwable = getException();
122             if (throwable != null) {
123                 if (this.fileName != null) {
124                     output.print("Caused in "); //$NON-NLS-1$
125
output.print(this.fileName);
126                     output.print(" by: "); //$NON-NLS-1$
127
} else {
128                     output.print("Caused by: "); //$NON-NLS-1$
129
}
130                 throwable.printStackTrace(output);
131             }
132         }
133     }
134 }
135
Popular Tags