Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

C# - Handling Exceptions

using System;

namespace ErrorHandlingApplication {

   class DivNumbers {
      int result;
      
      DivNumbers() {
         result = 0;
      }
      
      public void division(int num1, int num2) {
          /*
           result = num1 / num2;
           Console.WriteLine("Result: {0}", result);
           */
           
         try {
            result = num1 / num2;
            // int r1 = num1 + num2;
         } catch (DivideByZeroException exp) {
            Console.WriteLine("Exception caught: :-\n{0}", exp);
             Console.WriteLine("end! ");
         } finally {
            Console.WriteLine("Result: {0}", result);
         }
      }
      
      static void Main(string[] args) {
         DivNumbers d = new DivNumbers();
         d.division(25, 9);
         Console.ReadKey();
      }
   }
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.