c# 从零到精通-异常处理try…catch

c# 从零到精通-异常处理try…catch
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test01
{
class Program
{
static void Main(string[] args)
{
try //使用try…catch语句
{
object obj = null; //声明一个object变量,初始值为null
int N = (int)obj; //将object类型强制转换成int类型
}
catch (Exception ex) //捕获异常
{
Console.WriteLine(“捕获异常:” + ex); //输出异常
}
Console.ReadLine();

    }
}

}

猜你喜欢

转载自blog.csdn.net/weixin_43931979/article/details/131320809