Export (0) Print
Expand All
Expand Minimize

Troubleshooting Exceptions: System.FormatException

A FormatException exception is thrown by a method when the format of an argument does not meet the parameter specifications of the method.

For example, many of the data types defined in the System namespace include a Parse method that takes a string argument and converts it to the data type. These methods throw a FormatException if the supplied argument is not in a format that can be converted. Double.Parse will throw a FormatException if its string argument is not in a recognizable numeric format.

' The first three statements run correctly.




' The following statement throws a FormatException.

' Console.WriteLine(Double.Parse("32 115"))

Similarly, Boolean.Parse throws this exception if the string argument is not either "True" or "False".

' This statement runs correctly.


' This statement throws a FormatException.

' Console.WriteLine(Boolean.Parse("Ture"))

Make sure your method arguments are in the right format.

The format of your method arguments must meet the parameter specifications of the invoked members.

Community Additions

© 2015 Microsoft