Csharp/C Sharp by API/System/DivideByZeroException

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

DivideByZeroException.Message

<source lang="csharp"> using System; public class MainClass {

 public static void Main()
 {
   try
   {
     int zero = 0;
     Console.WriteLine("In try block: attempting division by zero");
     int myInt = 1 / zero;  // throws the exception
   }
   catch (DivideByZeroException myException)
   {
     // code that handles a DivideByZeroException
     Console.WriteLine("Message = " + myException.Message);
     Console.WriteLine("StackTrace = " + myException.StackTrace);
   }
 }

}

 </source>