博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

C# try catch finally

Posted on 2020-06-18 12:11  凤凰火舞  阅读(200)  评论(0编辑  收藏  举报

情形1: 

try
{
    int i = 0;
    i = int.Parse("t");
    Console.WriteLine("Try");
}
catch (Exception e)
{
    Console.WriteLine("Catch");
}
finally
{
    Console.WriteLine("Finally");
}

Console.WriteLine("End");

情形2:  

try
{
    int i = 0;
    i = int.Parse("t");
Console.WriteLine("Try");   }
finally { Console.WriteLine("Finally"); } Console.WriteLine("End");

 情形3:  

try
{
    int i = 0;
    i = int.Parse("t");
Console.WriteLine("Try"); }
catch (Exception e) { Console.WriteLine("Catch"); } Console.WriteLine("End");

  情形4:  

try
{
    int i = 0;
    i = int.Parse("12");
Console.WriteLine("Try"); }
catch (Exception e) { Console.WriteLine("Catch"); } finally { Console.WriteLine("Finally"); } Console.WriteLine("End");

 

 情形5:

int i = 0;
i = int.Parse("t");

Console.WriteLine("End");