9

.NET 中的 FormatException 是否等同于 Java 中的 NumberFormatException?

4

3 回答 3

8

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

于 2011-12-14T09:11:33.817 回答
3

Yes. Methods like Double.Parse throw a FormatException if the string to be converted does not represent a number in a valid format.

于 2011-12-14T09:09:48.233 回答
0

Yes, FormatException is thrown when you try to parse a number from a string with an invalid format (actually it's limited to numbers).

于 2011-12-14T09:08:20.167 回答