dwt2 help

Saaa empty at needmail.com
Wed Mar 25 16:29:44 PDT 2009


I filled in the Phobos implementation, but I'm not sure if it is all correct 
as I don't fully understand the exception handling.

module java.lang.Byte;

import java.lang.util;
import java.lang.exceptions;

version(Tango){
    static import tango.text.convert.Integer;
} else { // Phobos
    static import std.conv;
}
class Byte : ValueWrapperT!(byte) {
    public static byte parseByte( String s ){
        version(Tango){
            try{
                int res = tango.text.convert.Integer.parse( s );
                if( res < byte.min || res > byte.max ){
                    throw new NumberFormatException( "out of range" );
                }
                return res;
            }
            catch( IllegalArgumentException e ){
//How does this work? It catches e and gives it as an argument to a new 
exception.
                throw new NumberFormatException( e );
            }
        } else if version(Phobos){ // Phobos
            try{
                byte res = to!(byte)(s);
                return res;
            }
            catch(Object e){ // ConvError or ConvOverflowError
//Is this the correct translation?
                throw new NumberFormatException( e );
            }
            return 0;
        }
    }
    this( byte value ){
        super( value );
    }

    public static String toString( byte i ){
        return String_valueOf(i);
    }

}
alias Byte ValueWrapperByte; 




More information about the Digitalmars-d-learn mailing list