Advertisement
RupeshAcharya60

Exception Handling with C#

Jun 15th, 2022 (edited)
895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.64 KB | None | 0 0
  1. static void Main(string[] args)
  2.         {
  3.  
  4.             //Exception handling with C#
  5.             int a = 0;
  6.             int b = 5;
  7.             int[] x = { 1, 2, 3 };
  8.  
  9.             try
  10.             {
  11.                 int y = b / a;
  12.             }
  13.             catch(DivideByZeroException ex)
  14.             {
  15.                 Console.WriteLine("Cannot Divide By Zero");
  16.             }
  17.             try
  18.             {
  19.                 Console.WriteLine(x[12]);
  20.             }
  21.             catch(IndexOutOfRangeException ex)
  22.             {
  23.                 Console.WriteLine("Index Out of bound");
  24.             }
  25.  
  26.             Console.ReadKey();
  27.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement