Troubleshooting Exceptions: System.FormatException
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

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.

© 2015 Microsoft