Mega Code Archive

 
Categories / C# / Language Basics
 

Illustrates how to handle a specific exception

/* Mastering Visual C# .NET by Jason Price, Mike Gunderloy Publisher: Sybex; ISBN: 0782129110 */ /*   Example13_3.cs illustrates how to handle a specific exception */ using System; public class Example13_3 {   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);     }   } }