zoukankan      html  css  js  c++  java
  • 面向对象(自定义异常)

    /**
    * Created by Administrator on 2014/9/29.
    *
    * 自定义异常,需要继承Exception.
    */

    //copyright©liupengcheng
    //
    http://www.cnblogs.com/liupengcheng
    class fushuException extends Exception
    {
        fushuException(String msg)
        {
            super(msg);
        }
    }

    //copyright©liupengcheng
    //
    http://www.cnblogs.com/liupengcheng

    class Demo5
    {
        int div(int a,int b)    throws fushuException //fushuException    自定义负数异常
        {
            if(b<0)
                throw new fushuException("出现了除数是负数的情况");
            return a/b;
        }
    }

    //copyright©liupengcheng
    //
    http://www.cnblogs.com/liupengcheng


    public class ExceptionDemo3 {
        public static void main(String [] args)
        {
            Demo5 d = new Demo5();
            try
            {
                int x = d.div(4,-1);
                System.out.println("x"+ x);
            }
            catch(fushuException e)
            {
                System.out.println(e.toString());
            }

            System.out.println("over");
        }
    }

    //copyright©liupengcheng
    //
    http://www.cnblogs.com/liupengcheng

  • 相关阅读:
    Arr
    class4
    class3联大网页
    class33
    class3
    人机交换 NO 1书签
    大数据的框架与特点
    mapreduce排序
    mapreduce求平均数
    mapreduce去重
  • 原文地址:https://www.cnblogs.com/liupengcheng/p/4000167.html
Copyright © 2011-2022 走看看