9

Is FormatException in .NET the equivalent of NumberFormatException in Java ?

casperOne
  • 73,706
  • 19
  • 184
  • 253
Kenzo
  • 1,767
  • 8
  • 30
  • 53

3 Answers3

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

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
Hemant Metalia
  • 29,730
  • 18
  • 72
  • 91
3

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

kol
  • 27,881
  • 12
  • 83
  • 120
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).

Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758