Mercurial > projects > dwt-linux
annotate dwt/DWTError.d @ 361:4bffbf81e2d6
redirect direct prints to DwtLogger
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Fri, 20 Mar 2009 21:00:06 +0100 |
parents | c0d810de7093 |
children |
rev | line source |
---|---|
72 | 1 /******************************************************************************* |
259 | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
0 | 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 | |
72 | 10 * Port to the D programming language: |
11 * Frank Benoit <benoit@tionex.de> | |
0 | 12 *******************************************************************************/ |
71 | 13 module dwt.DWTError; |
0 | 14 |
238 | 15 import dwt.dwthelper.utils; |
16 | |
71 | 17 import dwt.DWT; |
0 | 18 |
19 import tango.core.Exception; | |
20 | |
21 /** | |
22 * This error is thrown whenever an unrecoverable error | |
71 | 23 * occurs internally in DWT. The message text and error code |
0 | 24 * provide a further description of the problem. The exception |
25 * has a <code>throwable</code> field which holds the underlying | |
26 * throwable that caused the problem (if this information is | |
27 * available (i.e. it may be null)). | |
28 * <p> | |
29 * SWTErrors are thrown when something fails internally which | |
71 | 30 * either leaves DWT in an unknown state (eg. the o/s call to |
31 * remove an item from a list returns an error code) or when DWT | |
0 | 32 * is left in a known-to-be-unrecoverable state (eg. it runs out |
33 * of callback resources). SWTErrors should not occur in typical | |
34 * programs, although "high reliability" applications should | |
35 * still catch them. | |
36 * </p><p> | |
71 | 37 * This class also provides support methods used by DWT to match |
38 * error codes to the appropriate exception class (DWTError, | |
39 * DWTException, or IllegalArgumentException) and to provide | |
40 * human readable strings for DWT error codes. | |
0 | 41 * </p> |
42 * | |
71 | 43 * @see DWTException |
44 * @see DWT#error(int) | |
259 | 45 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> |
0 | 46 */ |
47 | |
71 | 48 public class DWTError : PlatformException { |
0 | 49 /** |
71 | 50 * The DWT error code, one of DWT.ERROR_*. |
0 | 51 */ |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
52 public int code; |
0 | 53 |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
54 /** |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
55 * The underlying throwable that caused the problem, |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
56 * or null if this information is not available. |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
57 */ |
231
654b7d7cc33c
instead of throwable member var, use the Exception.next
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
58 public Exception throwable( Exception e ){ |
654b7d7cc33c
instead of throwable member var, use the Exception.next
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
59 this.next = e; |
654b7d7cc33c
instead of throwable member var, use the Exception.next
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
60 return this.next; |
654b7d7cc33c
instead of throwable member var, use the Exception.next
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
61 } |
654b7d7cc33c
instead of throwable member var, use the Exception.next
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
62 public Exception throwable(){ |
654b7d7cc33c
instead of throwable member var, use the Exception.next
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
63 return this.next; |
654b7d7cc33c
instead of throwable member var, use the Exception.next
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
64 } |
0 | 65 |
66 //static final long serialVersionUID = 3833467327105808433L; | |
67 | |
68 /** | |
69 * Constructs a new instance of this class with its | |
70 * stack trace filled in. The error code is set to an | |
71 * unspecified value. | |
72 */ | |
73 public this () { | |
71 | 74 this (DWT.ERROR_UNSPECIFIED); |
0 | 75 } |
76 | |
77 /** | |
78 * Constructs a new instance of this class with its | |
79 * stack trace and message filled in. The error code is | |
80 * set to an unspecified value. Specifying <code>null</code> | |
81 * as the message is equivalent to specifying an empty string. | |
82 * | |
83 * @param message the detail message for the exception | |
84 */ | |
238 | 85 public this (String message) { |
71 | 86 this (DWT.ERROR_UNSPECIFIED, message); |
0 | 87 } |
88 | |
89 /** | |
90 * Constructs a new instance of this class with its | |
91 * stack trace and error code filled in. | |
92 * | |
71 | 93 * @param code the DWT error code |
0 | 94 */ |
95 public this (int code) { | |
71 | 96 this (code, DWT.findErrorText (code)); |
0 | 97 } |
98 | |
99 /** | |
100 * Constructs a new instance of this class with its | |
101 * stack trace, error code and message filled in. | |
102 * Specifying <code>null</code> as the message is | |
103 * equivalent to specifying an empty string. | |
104 * | |
71 | 105 * @param code the DWT error code |
0 | 106 * @param message the detail message for the exception |
107 */ | |
238 | 108 public this (int code, String message) { |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
109 super (message); |
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
110 this.code = code; |
0 | 111 } |
112 | |
113 /** | |
114 * Returns the underlying throwable that caused the problem, | |
115 * or null if this information is not available. | |
116 * <p> | |
117 * NOTE: This method overrides Throwable.getCause() that was | |
118 * added to JDK1.4. It is necessary to override this method | |
119 * in order for inherited printStackTrace() methods to work. | |
120 * </p> | |
121 * @return the underlying throwable | |
122 * | |
123 * @since 3.1 | |
124 */ | |
125 public Exception getCause() { | |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
126 return throwable; |
0 | 127 } |
128 | |
129 /** | |
71 | 130 * Returns the string describing this DWTError object. |
0 | 131 * <p> |
132 * It is combined with the message string of the Throwable | |
71 | 133 * which caused this DWTError (if this information is available). |
0 | 134 * </p> |
71 | 135 * @return the error message string of this DWTError object |
0 | 136 */ |
238 | 137 public String getMessage () { |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
138 if (throwable is null) |
0 | 139 return super.toString(); |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
140 return super.toString () ~ " (" ~ throwable.toString () ~ ")"; //$NON-NLS-1$ //$NON-NLS-2$ |
0 | 141 } |
142 | |
143 /** | |
144 * Outputs a printable representation of this error's | |
145 * stack trace on the standard error stream. | |
146 * <p> | |
147 * Note: printStackTrace(PrintStream) and printStackTrace(PrintWriter) | |
148 * are not provided in order to maintain compatibility with CLDC. | |
149 * </p> | |
150 */ | |
151 public void printStackTrace () { | |
361
4bffbf81e2d6
redirect direct prints to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
259
diff
changeset
|
152 getDwtLogger().error( "stacktrace follows (if feature compiled in)" ); |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
72
diff
changeset
|
153 foreach( msg; info ){ |
361
4bffbf81e2d6
redirect direct prints to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
259
diff
changeset
|
154 getDwtLogger().error( "{}", msg ); |
0 | 155 } |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
156 if ( throwable !is null) { |
361
4bffbf81e2d6
redirect direct prints to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
259
diff
changeset
|
157 getDwtLogger().error ("*** Stack trace of contained error ***"); //$NON-NLS-1$ |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
72
diff
changeset
|
158 foreach( msg; throwable.info ){ |
361
4bffbf81e2d6
redirect direct prints to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
259
diff
changeset
|
159 getDwtLogger().error( "{}", msg ); |
0 | 160 } |
59
8cec8f536af3
All D sources complete gvim retab (4 spaces), bug with Composite moveAbove/moveBelow fixed.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
161 } |
0 | 162 } |
163 | |
164 } |