C# try catch finally

情形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");

C# try catch finally

情形2:  

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

C# try catch finally

 情形3:  

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

C# try catch finally

  情形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");

 C# try catch finally

 情形5:

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

Console.WriteLine("End");

C# try catch finally

 

C# try catch finally

上一篇:简单聊下.NET6 Minimal API的使用方式


下一篇:浅讲.Net 6 并与之前版本写法对比