Check OverflowException for long : Predefined Exception « Language Basics « C# / CSharp Tutorial






using System;

class MainClass
{
  static void Main(string[] args)
  {
    int MyInt = 12345000;
    long MyLong = MyInt;
    
    try
    {
      long c = checked(MyLong * 5000000);
    }
    catch (OverflowException e)
    {
      Console.WriteLine(e);
    }

  }

}








1.23.Predefined Exception
1.23.1.Use the NullReferenceException.
1.23.2.Throwing Exceptions: ArgumentNullException
1.23.3.Handle ArgumentOutOfRangeException
1.23.4.Check OverflowException for long
1.23.5.Generate an index out-of-bounds exception
1.23.6.Define exception variable in catch statement: DivideByZeroException