C# OverflowException


OverflowException is thrown when the parameter value is out of integer ranges.

Let us see an example.

When we set a value to int.Parse() method that is out of integer range, then OverflowException is thrown as shown below −

Example

 Live Demo

using System;
class Demo {
   static void Main() {
      string str = "757657657657657";
      int res = int.Parse(str);
   }
}

Output

The following error is thrown when the above program is compiled since we have passed a value that is out of integer (Int32) range.

Unhandled Exception:
System.OverflowException: Value was either too large or too small for an Int32.

Updated on: 23-Jun-2020

657 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements