关闭

捕捉异常 (Visual C#)

243人阅读 评论(0) 收藏 举报
C#
int top = 0, bottom = 0, result = 0;

try
{
    result = top / bottom;
}
catch (System.Exception ex)
{
    System.Console.WriteLine("{0} exception caught here.", ex.GetType().ToString());
    System.Console.WriteLine(ex.Message);
}
finally
{
    System.Console.WriteLine("Clean-up code executes here...");
}
System.Console.WriteLine("Program execution continues here...");

输出

System.DivideByZeroException exception caught here.
Attempted to divide by zero.
Clean-up code executes here...
Program execution continues here...
 
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:6919次
    • 积分:198
    • 等级:
    • 排名:千里之外
    • 原创:13篇
    • 转载:0篇
    • 译文:0篇
    • 评论:1条
    文章存档
    最新评论