finally与return

来源:互联网 发布:linux 硬盘分区 编辑:程序博客网 时间:2024/05/22 16:02

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication21
{
    class Program
    {
        static void Main(string[] args)
        {
            //return;//finally 里面的内容不会执行
            try
            {
                return;//finally 里面的内容会执行
            }
            catch (Exception ex)
            {


            }
            finally
            {
                Console.WriteLine("finallly");
                //throw new Exception("justatest");
                int a = divide(3,0);//仍然会抛出异常

            }           
        }
        static int divide(int a, int b)
        {
            return a / b;
        }
    }
}

原创粉丝点击