直接上代码实例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
try
{
// Convert.ToInt32("abcdefg");
Convert.ToInt32("123");
}
catch (Exception ex) //当程序转换abcdefg时。会有异常出现,则执行这段
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
finally//当程序转换123时,没有异常,执行完后,会再执行这段.
{
Console.WriteLine("过来了");
}
Console.ReadKey();
}
}
}