JAVA自定义异常抛出

JAVA自定义异常抛出 throw new Exception(“自定义异常提示”)在catch中处理异常

案例:

package demo;


public class Test4 {

    public static void hi(){
        try{
            throw new RuntimeException("high");
        }catch (Exception e){
            e.printStackTrace();
            System.out.println(e.getMessage());//high
        }
    }

    public static void main(String[] args) {
        Test4.hi();
    }
}

执行结果:

 

posted @ 2020-09-30 09:52  LW_20171224  阅读(168)  评论(0)    收藏  举报