Uncaught Divide by Zero Exception - CSharp Custom Type

CSharp examples for Custom Type:Exception

Description

Uncaught Divide by Zero Exception

Demo Code

using System;/*from www .j  av a 2  s. c  o  m*/
class MyClass
{
   public static void Main()
   {
      Console.WriteLine("Entering MyClass.Main");
      YourClass yourObject = new YourClass();
      yourObject.Method1();
      Console.WriteLine("Leaving MyClass.Main");
   }
}
class YourClass
{
   public void Method1()
   {
      Console.WriteLine("Entering YourClass.Method1");
      Method2();
      Console.WriteLine("Leaving YourClass.Method1");
   }
   public void Method2()
   {
      Console.WriteLine("Entering YourClass.Method2");
      int myInt = 0;
      int yourInt;
      //Dividing by zero
      yourInt = 10 / myInt;
      Console.WriteLine("Leaving YourClass.Method2");
   }
}

Result


Related Tutorials