Throw a format exception purposely to demonstrate catching a FormatException

image_pdfimage_print
   

/*
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);
            }
        }
    }
}