我是一个初学者,我想问一下,下面的程序运行结果是不是这样???
结果:
divided error!!!
programm end!!!
all main programm end!!!
程序:
using System;
using System.Collections.Generic;
using System.Text;namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int x, y;
            x=3;y=0;
            morecatchmethod(x,y);
            console.writeline("all main programm end!!!");
        }
        static void morecatchmethod(int x, int y)
        {
            int z;
            try
            {
               z=(int)x / y;
               Console.WriteLine("{0}", z);
            }
            catch (DivideByZeroException ex)
            {
                Console.WriteLine("divided error!!!");
            }
            Console.WriteLine("programme end!!!");
        }
    }
}

解决方案 »

  1.   

    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                int x, y;
                x=3;y=0;  //y=0 
                morecatchmethod(x,y);//调用y
                console.writeline("all main programm end!!!");
            }
            static void morecatchmethod(int x, int y)
            {
                int z;
                try
                {
                  z=(int)x / y;//y=0,被0除错
                  Console.WriteLine("{0}", z);
                }
                catch (DivideByZeroException ex)
                {
                    Console.WriteLine("divided error!!!");
                }
                Console.WriteLine("programme end!!!");
            }
        }
    }
      

  2.   

    static void morecatchmethod(int x, int y)
            {
                int z;
                try
                {
                  z=(int)x / y;
                  Console.WriteLine("{0}", z);
                }
                catch (DivideByZeroException ex)
                {
                    Console.WriteLine("divided error!!!");
                }
                Console.WriteLine("programme end!!!");
            //这里加个 catch吧 不然 你的try 没有意义了
              catch(错误信息)
               {提示}
            }