illustrates how to handle a specific exception : Exception Try Catch : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » Exception Try Catch »

 

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);

    }

  }

}


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» Exception Try Catch