黑马程序员技术交流社区

标题: 额,这是自定义异常的处理 [打印本页]

作者: 大奔    时间: 2015-2-5 10:01
标题: 额,这是自定义异常的处理
class personException extends Exception
{
       
}

class Demo
{
        public int  show(int x,int y) throws personException
        {
                if(y<0)
                        throw new personException();
                return x/y;
        }
}
class exceptionDemo
{
        public static void main(String[] args)
        {
                Demo d=new Demo();
                try
                {
                        int z=d.show(4,-1);
                        System.out.println(z);       
                }
                catch (personException e)
                {
                        System.out.println("负数出现了");
                       
                }
                System.out.println("over");
        }
}






欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2