亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#中的try catch finally用法分析

 更新時(shí)間:2014年12月26日 10:02:19   投稿:shichen2014  
這篇文章主要介紹了C#中的try catch finally用法,以實(shí)例形式分析了try catch finally針對(duì)錯(cuò)誤處理時(shí)的不同用法,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了C#中的try catch finally用法。分享給大家供大家參考。具體分析如下:

try中的程序塊是有可能發(fā)生錯(cuò)誤的程序塊,catch中的程序塊是當(dāng)發(fā)生錯(cuò)誤的時(shí)候才會(huì)執(zhí)行的代碼塊,finally中的程序塊是無(wú)論是否發(fā)生錯(cuò)誤都會(huì)執(zhí)行的代碼塊。

示例程序:

復(fù)制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace Sample_01_CA
{
    public class Complex
    {
        static void Main(string[] args)
        {
            int i = 2008;
            int j = 0;
            try
            {
                int result = i / j;
            }
            catch
            {
                Console.WriteLine("J變量的值為0");
            }
            finally
            {
                Console.WriteLine(j.ToString());
            }
            Console.Read();
        }
    };
}

程序輸出為:

J變量的值為0

0

示例程序:

復(fù)制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace Sample_01_CA
{
    public class Complex
    {
        static void Main(string[] args)
        {
            int i = 2008;
            int j = 2;
            try
            {
                int result = i / j;
            }
            catch
            {
                Console.WriteLine("J變量的值為0");
            }
            finally
            {
                Console.WriteLine(j.ToString());
            }
            Console.Read();
        }
    };
}

程序輸出為:

0

希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論