コード例 #1
0
        static void Main(string[] args)
        {
            // Here’s the exception handler.
            try
            {
                // Call factorial in a loop from 6 down to -6.
                for (int i = 6; i > -6; i--)
                {
                    // Calculate the factorial of the number.
                    int factorial = MyMathFunctions.Factorial(i);

                    // Display the result of each pass.
                    Console.WriteLine("i = {0}, factorial = {1}",
                                      i, factorial);
                }
            }
            catch (ArgumentException e)
            {
                // This is a "last-chance" exception handler.
                // Probably all you can do here is alert the user before quitting.
                Console.WriteLine("Fatal error:");

                // When you're ready to release the program, change this
                // output to something in plain English, preferably with guide-
                // lines for what to do about the problem.
                Console.WriteLine(e.ToString());
            }

            // Wait for user to acknowledge.
            Console.WriteLine("Press Enter to terminate...");
            Console.Read();
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            try
            {
                // call factorial in a loop from 6 down to -6.
                for (int i = 6; i > -6; i--)
                {
                    // calculate the factorial of the number
                    double dFactorial = MyMathFunctions.Factorial(i);

                    // display the result of each pass
                    Console.WriteLine("i = {0}, factorial = {1}",
                                      i, MyMathFunctions.Factorial(i));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Fatal error:");
                Console.WriteLine(e.ToString());
            }

            // wait for user to acknowledge
            Console.WriteLine("Press Enter to terminate...");
            Console.Read();
        }