Throw a format exception purposely to demonstrate catching a FormatException : Exception Try Catch : Language Basics C# Source Code


Custom Search

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

 

Throw a format exception purposely to demonstrate catching a FormatException








    

/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/

//
// FormExce.cs -- This program will throw a format exception purposeely
//                to demonstrate catching a FormatException.
//
//                Compile this program with the following command line:
//                    C:>csc FormExcep.cs
//
namespace nsExceptions
{
    using System;
    public class FormExce
    {
        static public void Main ()
        {
            const double pi = 3.14159;
            try
            {
                Console.WriteLine ("pi = {0,0:f5", pi);
            }
            catch (FormatException e)
            {
                Console.WriteLine (e.Message);
            }
        }
    }
}


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» Exception Try Catch