Программирование - это просто
Advertisement
arrow C# arrow Visual C# arrow Visual C# . 8. (try,catch,exception)
07.02.2023 .
1:
C#
Delphi
Web-
Excel-
.
Visual C# . 8. (try,catch,exception) E-mail
megabax   
28.11.2011 .
Delphi

Visual C# . 8. (try,catch,exception)

 

. , - , . , . . - , . , . - . . , , , . , , , .

. C# , . ( ), . "" . - . C# , .

( ):

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace ConsoleApplication1

{

    class Program

    {

        static void M1(int x, int y, int z)

        {

            try

            {

                int a = checked((int)Math.Pow(x, y));

                Console.WriteLine("x ^ y / z = {0}", a / z);

            }

            catch (DivideByZeroException)

            {

                Console.WriteLine(" ");

            }

            Console.WriteLine("M1 - ");

        }

 

        static void M2(int x, int y, int z)

        {

            try

            {

                M1(x, y, z);

            }

            catch (ArithmeticException)

            {

                Console.WriteLine(" ");

            }

            Console.WriteLine("M2 - ");

        }

 

 

        static void Main(string[] args)

        {

            Console.Write("x=");

            int x = int.Parse(Console.ReadLine());

            Console.Write("y=");

            int y = int.Parse(Console.ReadLine());

            Console.Write("z=");

            int z = int.Parse(Console.ReadLine());

            M2(x, y, z);

            Console.ReadLine();

        }

    }

}

x, y z,

xy/z

Visual C#  .  8.   (try,catch,exception)

, z 0? , :

Visual C#  .  8.   (try,catch,exception)

:

            try

            {

                int a = checked((int)Math.Pow(x, y));

                Console.WriteLine("x ^ y / z = {0}", a / z);

            }

            catch (DivideByZeroException)

            {

                Console.WriteLine(" ");

            }

:

Visual C#  .  8.   (try,catch,exception)

  catch, . , , , .

catch . , DivideByZero. . . , , M1 - , M2

            try

            {

                M1(x, y, z);

            }

            catch (ArithmeticException)

            {

                Console.WriteLine(" ");

            }

:

Visual C#  .  8.   (try,catch,exception)

 


, *,   "Microsoft Visual Studio 2010 Professional", Microsoft.. 


 

 

()

 

( 14.04.2014 . )
 
« .   . »
 
© 2023 Программирование - это просто
Joomla! - , GNU/GPL.
© 2005-2008 Joom.Ru - Joomla!
Design by Mamboteam.com | Powered by Mambobanner.de
  .