Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
FormatException in C#
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.
Advertisements
