.NET 中的 FormatException 是否等同于 Java 中的 NumberFormatException?
3 回答
I think yes both are same following are the details given about both Exception
NumberFormatException (java) : -Thrown to indicate that the application has attempted to convert a string to one of the numeric types, but that the string does not have the appropriate format.
FormatException (.net) : - FormatException is thrown when the format of an argument in a method invocation does not match the format of the corresponding formal parameter type. For example, if a method specifies a String parameter consisting of two digits with an embedded period, passing a corresponding string argument containing only two digits to that method would cause FormatException to be thrown.
FormatException uses the HRESULT COR_E_FORMAT, which has the value 0x80131537.
refer http://msdn.microsoft.com/en-us/library/system.formatexception.aspx
http://docs.oracle.com/javase/6/docs/api/java/lang/NumberFormatException.html
Yes. Methods like Double.Parse
throw a FormatException if the string to be converted does not represent a number in a valid format.
Yes, FormatException
is thrown when you try to parse a number from a string with an invalid format (actually it's limited to numbers).