KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > runtime > CoreException


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.core.runtime;
12
13 import java.io.PrintStream JavaDoc;
14 import java.io.PrintWriter JavaDoc;
15
16 /**
17  * A checked exception representing a failure.
18  * <p>
19  * Core exceptions contain a status object describing the
20  * cause of the exception.
21  * </p><p>
22  * This class can be used without OSGi running.
23  * </p>
24  * @see IStatus
25  */

26 public class CoreException extends Exception JavaDoc {
27
28     /**
29      * All serializable objects should have a stable serialVersionUID
30      */

31     private static final long serialVersionUID = 1L;
32
33     /** Status object. */
34     private IStatus status;
35
36     /**
37      * Creates a new exception with the given status object. The message
38      * of the given status is used as the exception message.
39      *
40      * @param status the status object to be associated with this exception
41      */

42     public CoreException(IStatus status) {
43         super(status.getMessage());
44         this.status = status;
45     }
46
47     /**
48      * Returns the status object for this exception.
49      *
50      * @return a status object
51      */

52     public final IStatus getStatus() {
53         return status;
54     }
55
56     /**
57      * Prints a stack trace out for the exception, and
58      * any nested exception that it may have embedded in
59      * its Status object.
60      */

61     public void printStackTrace() {
62         printStackTrace(System.err);
63     }
64
65     /**
66      * Prints a stack trace out for the exception, and
67      * any nested exception that it may have embedded in
68      * its Status object.
69      *
70      * @param output the stream to write to
71      */

72     public void printStackTrace(PrintStream JavaDoc output) {
73         synchronized (output) {
74             super.printStackTrace(output);
75             if (status.getException() != null) {
76                 output.print(getClass().getName() + "[" + status.getCode() + "]: "); //$NON-NLS-1$ //$NON-NLS-2$
77
status.getException().printStackTrace(output);
78             }
79         }
80     }
81
82     /**
83      * Prints a stack trace out for the exception, and
84      * any nested exception that it may have embedded in
85      * its Status object.
86      *
87      * @param output the stream to write to
88      */

89     public void printStackTrace(PrintWriter JavaDoc output) {
90         synchronized (output) {
91             super.printStackTrace(output);
92             if (status.getException() != null) {
93                 output.print(getClass().getName() + "[" + status.getCode() + "]: "); //$NON-NLS-1$ //$NON-NLS-2$
94
status.getException().printStackTrace(output);
95             }
96         }
97     }
98
99 }
100
Popular Tags