Thu, 26 Mar 2009 01:40:25 +0100, Saaa wrote: >>> [...] >>> >>> catch(Object e){ // ConvError or ConvOverflowError >>> //Is this the correct translation? >>> throw new NumberFormatException( e ); >>> } >> >> It depends on what NumberFormatException can accept as an argument. If >> it accepts an Object then it's fine. > > class NumberFormatException : IllegalArgumentException { > this( String e ){ > super(e); > } > this( Exception e ){ > super(e.toString); > } > } > > Can Object be implicitly converted to Exception?
No it cannot. Object is the root of the D class hierarchy. In D1 Exception is derived directly from Object. In D2 Exception is derived from Throwable which in turn is derived from Object. You can cast Exception to Object but not the other way around. What's worse, ConvError and ConvOverflowError in D2 are derived from Error which is a separate class from Exception and cannot be cast implicitly. I think you'd want to fix the NumberFormatException to accept Throwable for instance which is a base of both Exception and Error in D2.