Catching EXCEPTIONS in C#

Using TRY and CATCH blocks, you can catch the exceptions.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace ForgetCode
{
    class Program
    {
       static void Main(string[] args)
        {
            int top = 0, bottom = 0, result = 0;
            try
            {
                result = top / bottom;
            }
            catch (System.DivideByZeroException ex)
            {
                Console.WriteLine("{0} Exception caught.", ex);
            }
           
        }
    }
}


Output:
System.DivideByZeroException: Attempted to divide by zero.