zoukankan      html  css  js  c++  java
  • 面向对象(异常try-catch)

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

    /*
    * 异常的处理
    * try
    * {
    *   需要被检测的代码
    * }
    * catch(异常类 变量)
    * {
    *   处理异常的代码(处理方式)
    * }
    * finally
    * {
    *   一定会执行的语句
    * }
    * */

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

    class Demo3
    {
        int div(int a,int b) throws Exception //声明函数有可能出现异常
        {
            return a/b;
        }
    }

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


    public class ExceptionDemo {
        public static void main(String [] args)
        {
            Demo3 d = new Demo3();
            try
            {
                int x = d.div(4,0);
                System.out.println("x"+ x);
            }
            catch(Exception e)
            {
                System.out.println("除零了");
                System.out.println(e.getMessage());
            }

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

    //copyright©liupengcheng
    //http://www.cnblogs.com/liupengcheng
  • 相关阅读:
    2013年10月17日 搬出来了
    如何与领导相处
    WEB系统开发
    C++ 常用术语(后续补充)
    C++ 构造函数放置默认转换explicit关键字(2)
    工作与生活
    C++类型转化分析(1)
    (一)win7下cocos2d-x 21 + vs2010
    为了生活
    iOS
  • 原文地址:https://www.cnblogs.com/liupengcheng/p/3998331.html
Copyright © 2011-2022 走看看