FomatException is thrown when the format of an argument is invalid.
Let us see an example.
When we set a value other than int to int.Parse() method, then FormatException is thrown as shown below −
Example
using System;
class Demo {
static void Main() {
string str = "3.5";
int res = int.Parse(str);
}
}The following error is thrown when the above program is compiled since we have passed a value other than integer.
Output
Unhandled Exception: System.FormatException: Input string was not in a correct format.