try catch keywords

try/catch keywords in C#
The try block utilized to put the code inside the try block that may throw an exception wherein catch block utilized to take care of the exception.so let's see the example below which demonstrates try/catch block.

Program

using System;

    namespace try_catch
    {
        class Program
        {
            static void Main(string[] args)
            {
              try
             {
            int x = 50;
            int y = 0;
            int z = x / y;
              }

        catch (Exception ex)
              {
            Console.WriteLine(ex);
            Console.ReadKey();
              } 
            }
        }
    }

Output
System.DividedByZeroException: Attempted to divide by zero

Popular posts from this blog

Media Player in C# Visual Studio By Rohit Programming Zone

ImageEditor in C# Visual Studio 2017

Microsoft tools Download