ex-11-02

来自「Programming Csharp Source Code(代码) Prog」· 代码 · 共 43 行

TXT
43
字号
// Example 11-02: Catching an exception

namespace Programming_CSharp
{
    using System;

    public class Test
    {
        public static void Main()
        {
            Console.WriteLine("Enter Main...");
            Test t = new Test();
            t.Func1();
            Console.WriteLine("Exit Main...");           

        }

        public void Func1()
        {
            Console.WriteLine("Enter Func1...");
            Func2();
            Console.WriteLine("Exit Func1...");           
        }

        public void Func2()
        {
            Console.WriteLine("Enter Func2...");
            try
            {
                Console.WriteLine("Entering try block...");
                throw new System.Exception();                
                Console.WriteLine("Exiting try block...");
            }
            catch
            {
                Console.WriteLine(
                  "Exception caught and handled.");
            }
            Console.WriteLine("Exit Func2...");
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?