C#内置的异常

using System;namespace MyErrorHandlingApplication {class DivNumbers {int result;DivNumbers() {result = 0;

编程学习网为您整理以下代码实例,主要实现:C#内置的异常,希望可以帮到各位朋友。

using System;

namespace MyErrorHandlingApplication {

   class divNumbers {
      int result;

      divNumbers() {
         result = 0;
      }

      public voID mydivision(int num1, int num2) {
         try {
            result = num1 / num2;
         } catch (divIDeByZeroException e) {
            Console.Writeline("Exception Caught: {0}", e);
         } finally {
            Console.Writeline("Result: {0}", result);
         }
      }

      static voID Main(string[] args) {
         divNumbers d = new divNumbers();
         d.mydivision(5, 0);
         Console.ReadKey();
      }
   }
}

本文标题为:C#内置的异常

基础教程推荐