comparison org.eclipse.equinox.common/src/org/eclipse/core/runtime/CoreException.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children 735224fcc45f
comparison
equal deleted inserted replaced
11:43904fec5dca 12:bc29606a740c
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 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13 module org.eclipse.core.runtime.CoreException;
14
15 import org.eclipse.core.runtime.IStatus;
16
17 // import java.io.PrintStream;
18 // import java.io.PrintWriter;
19
20 import java.lang.all;
21 import tango.io.Stdout;
22
23 /**
24 * A checked exception representing a failure.
25 * <p>
26 * Core exceptions contain a status object describing the
27 * cause of the exception.
28 * </p><p>
29 * This class can be used without OSGi running.
30 * </p>
31 * @see IStatus
32 */
33 public class CoreException : Exception {
34
35 /**
36 * All serializable objects should have a stable serialVersionUID
37 */
38 private static const long serialVersionUID = 1L;
39
40 /** Status object. */
41 private IStatus status;
42
43 /**
44 * Creates a new exception with the given status object. The message
45 * of the given status is used as the exception message.
46 *
47 * @param status the status object to be associated with this exception
48 */
49 public this(IStatus status) {
50 super(status.getMessage());
51 this.status = status;
52 }
53
54 /**
55 * Returns the cause of this exception, or <code>null</code> if none.
56 *
57 * @return the cause for this exception
58 * @since 3.4
59 */
60 public Exception getCause() {
61 return status.getException();
62 }
63
64 /**
65 * Returns the status object for this exception.
66 * <p>
67 * <b>IMPORTANT:</b><br>
68 * The result must NOT be used to log a <code>CoreException</code>
69 * (e.g., using <code>yourPlugin.getLog().log(status);</code>),
70 * since that code pattern hides the original stacktrace.
71 * Instead, create a new {@link Status} with your plug-in ID and
72 * this <code>CoreException</code>, and log that new status.
73 * </p>
74 *
75 * @return a status object
76 */
77 public final IStatus getStatus() {
78 return status;
79 }
80
81 /**
82 * Prints a stack trace out for the exception, and
83 * any nested exception that it may have embedded in
84 * its Status object.
85 */
86 public void printStackTrace() {
87 // printStackTrace(System.err);
88 Stderr.formatln( "Exception in File {}({}): {}", this.file, this.line, this.msg );
89 foreach( msg; this.info ){
90 Stderr.formatln( " trc: {}", msg );
91 }
92 if (status.getException() !is null) {
93 Stderr.formatln( "{}[{}]: ", this.classinfo.name, status.getCode() ); //$NON-NLS-1$ //$NON-NLS-2$
94 // status.getException().printStackTrace();
95 auto e = status.getException();
96 Stderr.formatln( "Exception in File {}({}): {}", e.file, e.line, e.msg );
97 foreach( msg; e.info ){
98 Stderr.formatln( " trc: {}", msg );
99 }
100 }
101 }
102
103 //FIXME
104 // /**
105 // * Prints a stack trace out for the exception, and
106 // * any nested exception that it may have embedded in
107 // * its Status object.
108 // *
109 // * @param output the stream to write to
110 // */
111 // public void printStackTrace(PrintStream output) {
112 // synchronized (output) {
113 // super.printStackTrace(output);
114 // if (status.getException() !is null) {
115 // output.print(getClass().getName() + "[" + status.getCode() + "]: "); //$NON-NLS-1$ //$NON-NLS-2$
116 // status.getException().printStackTrace(output);
117 // }
118 // }
119 // }
120 //
121 // /**
122 // * Prints a stack trace out for the exception, and
123 // * any nested exception that it may have embedded in
124 // * its Status object.
125 // *
126 // * @param output the stream to write to
127 // */
128 // public void printStackTrace(PrintWriter output) {
129 // synchronized (output) {
130 // super.printStackTrace(output);
131 // if (status.getException() !is null) {
132 // output.print(getClass().getName() + "[" + status.getCode() + "]: "); //$NON-NLS-1$ //$NON-NLS-2$
133 // status.getException().printStackTrace(output);
134 // }
135 // }
136 // }
137
138 }