illustrates the use of a System.Exception object : Exception Class : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » Exception Class »

 

illustrates the use of a System.Exception object









    

/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy

Publisher: Sybex;
ISBN: 0782129110
*/

/*
  Example13_2.cs illustrates the use of a
  System.Exception object
*/

using System;

public class Example13_2
{

  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 (System.Exception myException)
    {

      // display the exception object's properties
      Console.WriteLine("HelpLink = " + myException.HelpLink);
      Console.WriteLine("Message = " + myException.Message);
      Console.WriteLine("Source = " + myException.Source);
      Console.WriteLine("StackTrace = " + myException.StackTrace);
      Console.WriteLine("TargetSite = " + myException.TargetSite);

    }

  }

}

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» Exception Class