Csharp/C Sharp/Language Basics/Try Catch — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 14:39, 26 мая 2010

Catch Block With Exception Object

<source lang="csharp"> using System; using System.Collections; class Class1 {

  static void Main(string[] args) {
   long lngResult;
   long lngValue = 0;
   try {
     lngResult = 8 / lngValue;
   }
   catch (Exception objE) {
     Console.WriteLine(objE.ToString());
   }
  }

}

      </source>


Catch without Exception type

<source lang="csharp">

   using System;
   using System.Collections;

class Class1 {

  static void Main(string[] args) {
   long lngResult;
   long lngValue = 0;
   try {
     lngResult = 8 / lngValue;
   }
   catch {
     Console.WriteLine("catch");
   }
   finally {
     Console.WriteLine("finally");
   }
  }

}


      </source>


try and catch exception

<source lang="csharp">

   using System;
   using System.Collections;

class Class1 {

  static void Main(string[] args) {
   long lngResult;
   long lngValue = 0;
   try {
     lngResult = 8 / lngValue;
   }
   catch {
     Console.WriteLine("catch");
   }
   finally {
     Console.WriteLine("finally");
   }
  }

}


      </source>


try catch with finally

<source lang="csharp">

   using System;
   using System.Collections;

class Class1 {

  static void Main(string[] args) {
   long lngResult;
   long lngValue = 0;
   try {
     lngResult = 8 / lngValue;
   }
   catch {
     Console.WriteLine("catch");
   }
   finally {
     Console.WriteLine("finally");
   }
  }

}


      </source>