
What could provoke an OverflowException? And how can you fix the problem in your C# program? An OverflowException is only thrown in a checked context. It alerts you to an integer overflow: a situation where the number becomes too large to be represented in the bytes.
This C# page describes the OverflowException. This exception is thrown in a checked context.
Let's look at this simple program. It declares a checked programming context inside the Main method. Next, we assign an int variable to one greater than the maximum value that can be stored in an int. An int is four bytes; more bytes would be needed to represent the desired number.
Program that causes OverflowException [C#]
class Program
{
static void Main()
{
checked
{
int value = int.MaxValue + int.Parse("1");
}
}
}
Output
Unhandled Exception: System.OverflowException: Arithmetic operation resulted in
an overflow.Result. What we end up with is an OverflowException. This could be trapped in a catch block if you needed to handle the problem at runtime. Using a checked context can help alert you to logic problems in your program faster.

With the checked context, bugs in our programs that would be silently ignored are changed into serious errors. Control flow is interrupted and programs are terminated. In the above program, if you use no checked context (or the unchecked context), the program proceeds like nothing is amiss. However, it doesn't give you the number you probably expect.
Checked Context Unchecked Context
The OverflowException is a useful way of learning of logical errors in our C# programs. With the checked context, we can detect these hard-to-find bugs and improve the logic of our software in a more systematic way.
Exception Handling