OverflowException : Buildin Exceptions « Development Class « C# / C Sharp






OverflowException

 

using System;

class MainClass
{
    public static void Main(){

        int value = 987000000;
        checked {
            try {
               // Square the original value.
               int square = value * value; 
               Console.WriteLine("{0} ^ 3 = {1}", value, square);
            }
            catch (OverflowException) {
               double square = Math.Pow(value, 2);
               Console.WriteLine("Exception: {0} > {1:E}.", square, Int32.MaxValue);
            } 
        }
    }
}

   
  








Related examples in the same category

1.Throw and Catch an IO exception because the file zxcvb.data doesn't exist
2.OutOfMemoryException Exception
3.StackOverflowException Exception
4.NullReferenceException Exception
5.InvalidCastException Exception
6.IndexOutOfRangeException Exception
7.OverflowException Exception
8.Throw Index Out Of Range Exception
9.Throw Null reference Exception
10.Throw Invalid Operation Exception
11.Argument Null Exception
12.Throw Argument Out Of Range Exception
13.ArgumentException is thrown when one of the arguments provided to a method is not valid.