Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 79 additions & 83 deletions base/src/java/lang/exceptions.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,79 @@ module java.lang.exceptions;
import java.lang.util;
import java.lang.String;

version(Tango){
static import tango.core.Exception;
public alias tango.core.Exception.IllegalArgumentException IllegalArgumentException;
public alias tango.core.Exception.IOException IOException;
public alias tango.core.Exception.PlatformException PlatformException;
public alias tango.core.Exception.ArrayBoundsException ArrayIndexOutOfBoundsException;
public alias tango.core.Exception.NoSuchElementException NoSuchElementException;
public alias tango.core.Exception.UnicodeException UnicodeException;
alias Exception Throwable;
} else { // Phobos

static import core.exception;
public alias core.exception.RangeError ArrayIndexOutOfBoundsException;

class PlatformException : Exception {
this( String e = null ){
super(e);
}
public import core.exception : ArrayIndexOutOfBoundsException = RangeError;

/**
* Thrown when an application tries to load in a class through its string
* name using:
*
* $(UL
* $(LI The `forName` method in class `Class`)
* $(LI The `findSystemClass` method in class `ClassLoader`)
* $(LI The `loadClass` method in class `ClassLoader`)
* )
*
* but not definition for the class with the specified name could be found.
*/
class ClassNotFoundException : Exception {
/**
* Constructs a new `ClassNotFoundException` with no detail provided.
*/
public this() {
super("null");
}

/**
* Constructs a new `ClassNotFoundException` with the provided detail.
*
* Params:
* s = The detail message.
*/
public this(String s) {
super(s);
}

/**
* Constructs a new `ClassNotFoundException` with the provided detail and
* optional exception that was raised while loading the class.
*
* Params:
* s = The detail message.
* ex = The exception that was raised while loading the class.
*/
public this(String s, Exception ex) {
super(s, ex);
}
}

class PlatformException : Exception {
this( String e = null ){
super(e);
}
}

class IllegalArgumentException : Exception {
this( String e = null ){
super(e);
}
class IllegalArgumentException : Exception {
this( String e = null ){
super(e);
}
}

class IOException : Exception {
this( String e = null ){
super(e);
}
class IOException : Exception {
this( String e = null ){
super(e);
}
}

class NoSuchElementException : Exception {
this( String e = null ){
super(e);
}
class NoSuchElementException : Exception {
this( String e = null ){
super(e);
}
}

class UnicodeException : Exception {
this( String msg, int idx){
super( "" );
}
class UnicodeException : Exception {
this( String msg, int idx){
super( "" );
}

}

class InternalError : Exception {
Expand Down Expand Up @@ -169,60 +198,27 @@ String ExceptionGetLocalizedMessage( Exception e ){
return e.msg;
}

version(Tango){
/// Extension to the D Exception
void ExceptionPrintStackTrace( Exception e ){
ExceptionPrintStackTrace( e, & getDwtLogger().error );
}

/// Extension to the D Exception
void ExceptionPrintStackTrace( Throwable e, void delegate ( String file, ulong line, String fmt, ... ) dg ){
Throwable exception = e;
while( exception !is null ){
dg( exception.file, exception.line, "Exception in {}({}): {}", exception.file, exception.line, exception.msg );
if( exception.info !is null ){
foreach( frame; exception.info ){
dg( exception.file, exception.line, "trc {} {}", frame.file, frame.line );
}
void ExceptionPrintStackTrace( Exception e ){
Throwable exception = e;
while( exception !is null ){
getDwtLogger().error( exception.file, exception.line, "Exception in {}({}): {}", exception.file, exception.line, exception.msg );
if( exception.info !is null ){
foreach( line, file; exception.info ){
getDwtLogger().error( exception.file, exception.line, "trc {} {}", file, line );
}
exception = exception.next;
}
}
} else { // Phobos
void ExceptionPrintStackTrace( Exception e ){
Throwable exception = e;
while( exception !is null ){
getDwtLogger().error( exception.file, exception.line, "Exception in {}({}): {}", exception.file, exception.line, exception.msg );
if( exception.info !is null ){
foreach( line, file; exception.info ){
getDwtLogger().error( exception.file, exception.line, "trc {} {}", file, line );
}
}
exception = exception.next;
}
exception = exception.next;
}
}

void PrintStackTrace( int deepth = 100, String prefix = "trc" ){
version(Tango){
auto e = new Exception( null );
int idx = 0;
const start = 3;
foreach( frame; e.info ){
if( idx >= start && idx < start+deepth ) {
getDwtLogger().trace( __FILE__, __LINE__, "{} {}: {}", prefix, frame.file, frame.line );
}
idx++;
}
} else { // Phobos
auto e = new Exception( null );
int idx = 0;
const start = 3;
foreach( line, file; e.info ){
if( idx >= start && idx < start+deepth ) {
getDwtLogger().trace( __FILE__, __LINE__, "{} {}: {}", prefix, file, line );
}
idx++;
auto e = new Exception( null );
int idx = 0;
const start = 3;
foreach( line, file; e.info ){
if( idx >= start && idx < start+deepth ) {
getDwtLogger().trace( __FILE__, __LINE__, "{} {}: {}", prefix, file, line );
}
idx++;
}
}