Troubleshooting Exceptions: System.FormatException
TOC
Collapse the table of content
Expand the table of content

Troubleshooting Exceptions: System.FormatException

Updated: August 2011

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. Consider the following examples.

' The first three statements run correctly.

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

Console.WriteLine(Double.Parse("32115"))

Console.WriteLine(Double.Parse("32.115"))

' 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.

Console.WriteLine(Boolean.Parse("True"))

' This statement throws a FormatException.

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

Make sure your method arguments are in the correct format.

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

Date

History

Reason

August 2011

Added two links

Customer feedback.

Community Additions

ADD
Show:
© 2016 Microsoft