xiaolizi007
11/25/2016 - 6:11 AM

try-catch-finally

try-catch-finally #csharp

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication7
{
    class Program
    {
        static void Main()
        {
            Console.WriteLine(Test());
            Console.ReadKey();
        }

        static int Test()
        {
            int num = 0;
            try
            {
                num = 1;
                throw new Exception("手动控制抛出异常");
                return num;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return num;
            }
            finally
            {
                num++;
                Console.WriteLine("我在Finally中num={0}", num);
            }
        }

    }
}