异常处理

案例代码如下:

class MyClass
    {
        public void A()
        {
            try
            {
                B();
            }
            catch (System.NullReferenceException)
            {
            Console.WriteLine("catch clause in A()");
        }
        finally
        {

            Console.WriteLine("finally clause in A()");

        }
        
    }
    private void B()
    {
        int x = 10, y = 0;
        try
        {
            x /= y;//除数不能为0;
        }
        catch (System.IndexOutOfRangeException )
        {

            Console.WriteLine("catch clause in B()");
        }
        finally
        {
            Console.WriteLine("finally clasue in B()");
        }


    }

上一篇:Java基础语法03


下一篇:java基础面试题----持续补充