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(); } }
执行结果: