![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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