shibazi

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

1.异常处理类

package second;

public class MyException extends Exception {

    MyException (){
        
    }
    MyException (String ErrorMsg){
        super(ErrorMsg);
    }
    public void check(){
        System.out.println("都报错了,还处理个毛线!");
    }
}

2.程序

package second;

public class ScoreCount {
    public static void main(String[] args){
        String end = "";
        try{
            end = score(1000);
        }catch(MyException e){
            e.check();
        }
        System.out.println(end);
    }
    /* 可能会爆出异常的方法 */
    static String score(int score) throws MyException {
        if(score <= 50){
            return "不及格!";
        }else if(score <= 80){
            return "优良!";
        }else if(score <= 100){
            return "好评!";
        }
        throw new MyException();
    }
}

 

posted on 2014-07-15 11:05  一生学习,何来毕业  阅读(199)  评论(0编辑  收藏  举报