Code Bye

玩转Exception,看谁玩得最开心

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace NestedException
{
    class Program
    {
        static void Main(string[] args)
        {
            try //Level1
            {
                try //Level2
                {
                    try  //Level3
                    {
                        //throw new Exception1();
                        //throw new Exception2();
                        //throw new Exception3();
                        //throw new InvalidOperationException();
                    }
                    catch (InvalidOperationException)
                    {
                        /// 专为InvalidOperationException异常,定制的处理语句
                        Console.WriteLine("\n在Level3中执行InvalidOperationException ");
                    }
                    catch (Exception3) //Level3
                    {
                        Console.WriteLine("\n在Level3中执行Exception3 ");
                    }
                    finally //Level3
                    {
                        Console.WriteLine("\n在Level3中执行finally ");
                    }
                }
                catch (Exception2) //Level2
                {
                    Console.WriteLine("\n在Level2中执行Exception2 ");
                }
                finally //Level2
                {
                    Console.WriteLine("\n在Level2中执行finally ");
                }
            }
            catch (Exception1) //Level1
            {
                Console.WriteLine("\n在Level1中执行Exception1 ");
            }
            catch (Exception ex)
            {
                Console.WriteLine("\n在Level1中执行Exception,注意是Exception ");
                Console.WriteLine(ex);
            }
            finally
            {
                Console.WriteLine("\n在Level1中执行finally ");
            }
            Console.ReadKey();//程序暂停
        }
    }
    class Exception1 : Exception
    {
    }
    class Exception2 : Exception
    {
    }
    class Exception3 : Exception
    {
    }
}

以上是一个测试try-catch-finally语句的C#代码,Let”s 玩!

解决方案

10

10

Exception都有专门的类定义,看门口狗穿警服–正规?
不明觉厉!

10

and so what?

20

玩什么?

10

引用:

and so what?

估计希望大版给推荐一个

10

and then?

10

不明觉厉。

10

本人和楼上们同样一脸的懵逼。

10

一脸懵逼

10


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明玩转Exception,看谁玩得最开心