comparison base/src/java/lang/exceptions.d @ 27:1bf55a6eb092

Renamed java tree to base
author Frank Benoit <benoit@tionex.de>
date Sat, 21 Mar 2009 11:33:57 +0100
parents java/src/java/lang/exceptions.d@f589fc20a5f9
children 66be6a990713
comparison
equal deleted inserted replaced
26:f589fc20a5f9 27:1bf55a6eb092
1 module java.lang.exceptions;
2
3 import java.lang.util;
4 import java.lang.String;
5
6 version(Tango){
7 static import tango.core.Exception;
8 public alias tango.core.Exception.IllegalArgumentException IllegalArgumentException;
9 public alias tango.core.Exception.IOException IOException;
10 public alias tango.core.Exception.PlatformException PlatformException;
11 public alias tango.core.Exception.ArrayBoundsException ArrayIndexOutOfBoundsException;
12 public alias tango.core.Exception.NoSuchElementException NoSuchElementException;
13 public alias tango.core.Exception.UnicodeException UnicodeException;
14 alias Exception Throwable;
15 } else { // Phobos
16
17 static import core.exception;
18 public alias core.exception.RangeError ArrayIndexOutOfBoundsException;
19
20 class PlatformException : Exception {
21 this( String e = null ){
22 super(e);
23 }
24 }
25
26 class IllegalArgumentException : Exception {
27 this( String e = null ){
28 super(e);
29 }
30 }
31
32 class IOException : Exception {
33 this( String e = null ){
34 super(e);
35 }
36 }
37
38 class NoSuchElementException : Exception {
39 this( String e = null ){
40 super(e);
41 }
42 }
43
44 class UnicodeException : Exception {
45 this( String msg, int idx){
46 super( "" );
47 }
48 }
49
50 }
51
52 class InternalError : Exception {
53 this( String file, long line, String e = null ){
54 super(e);
55 }
56 }
57
58 class ClassCastException : Exception {
59 this( String e = null ){
60 super(e);
61 }
62 }
63
64 class IllegalStateException : Exception {
65 this( String e = null ){
66 super(e);
67 }
68 this( Exception e ){
69 super(e.toString);
70 }
71 }
72
73 class IndexOutOfBoundsException : Exception {
74 this( String e = null){
75 super(e);
76 }
77 }
78
79 class InterruptedException : Exception {
80 this( String e = null ){
81 super(e);
82 }
83 this( Exception e ){
84 super(e.toString);
85 }
86 }
87
88 class NullPointerException : Exception {
89 this( String e = null ){
90 super(e);
91 }
92 this( Exception e ){
93 super(e.toString);
94 }
95 }
96
97 class NumberFormatException : IllegalArgumentException {
98 this( String e ){
99 super(e);
100 }
101 this( Exception e ){
102 super(e.toString);
103 }
104 }
105
106 class RuntimeException : Exception {
107 this( String file, long line, String msg = null){
108 super( msg, file, line );
109 }
110 this( String e = null){
111 super(e);
112 }
113 this( Exception e ){
114 super(e.toString);
115 next = e;
116 }
117 public Throwable getCause() {
118 return next; // D2 has next of type Throwable
119 }
120 }
121
122 class UnsupportedOperationException : RuntimeException {
123 this( String e = null){
124 super(e);
125 }
126 this( Exception e ){
127 super(e.toString);
128 }
129 }
130
131 /// Extension to the D Exception
132 String ExceptionGetLocalizedMessage( Exception e ){
133 return e.msg;
134 }
135
136 /// Extension to the D Exception
137 void ExceptionPrintStackTrace( Exception e ){
138 ExceptionPrintStackTrace( e, & getDwtLogger().error );
139 }
140
141 /// Extension to the D Exception
142 void ExceptionPrintStackTrace( Throwable e, void delegate ( String file, ulong line, String fmt, ... ) dg ){
143 Throwable exception = e;
144 while( exception !is null ){
145 dg( exception.file, exception.line, "Exception in {}({}): {}", exception.file, exception.line, exception.msg );
146 if( exception.info !is null ){
147 foreach( msg; exception.info ){
148 dg( exception.file, exception.line, "trc {}", msg );
149 }
150 }
151 exception = exception.next;
152 }
153 }
154
155 void PrintStackTrace( int deepth = 100, String prefix = "trc" ){
156 auto e = new Exception( null );
157 int idx = 0;
158 const start = 3;
159 foreach( msg; e.info ){
160 if( idx >= start && idx < start+deepth ) {
161 getDwtLogger().trace( __FILE__, __LINE__, "{}: {}", prefix, msg );
162 }
163 idx++;
164 }
165 }