zoukankan      html  css  js  c++  java
  • 异常处理

    1、throwable类  (异常抛出)
       tostring()  返回该异常的名字和详细的字符串
       getMessage() 返回该异常的提示信息
       printStackTrace() 返回该异常的所有信息
    2、try...Catch   (main方法中不用throwable,用try...catch处理)
       try{
            //需要被检测的语句
              }
        Catch(异常类 变量){
            //异常的处理语句
         }
        finally{
            //一定会被执行的语句
         }
    public static void main(String[] args){
            try {
                fun(-1);
            } catch (Exception e) {
                //e.printStackTrace();
              //System.out.println(e.toString());
                System.out.println(e.getMessage());
            }finally{
                System.out.println("最终的语句");
            }
        }
        public static double fun(int i){
            if(i<0)
                 throw new RuntimeException("元不存在");
                  return i*i*Math.PI;
        }
    }

  • 相关阅读:
    LeetCode OJ Remove Duplicates from Sorted Array II
    LeetCode OJ 75. Sort Colors
    LeetCode OJ 74. Search a 2D Matrix
    LeetCode OJ 73. Set Matrix Zeroes
    Taglist
    NERDTree
    Beyond Compare 4
    Beyond compare vs kdiff3
    切換 java compiler 版本
    PE+ 1.0 ( Pump Express Plus 1.0 )
  • 原文地址:https://www.cnblogs.com/fbbg/p/10623521.html
Copyright © 2011-2022 走看看