异常
class User{ private int age; public void setAge(int age){ if(age<0){ Exception r=new Exception("年龄不能为负数"); throw e; } this.age=age; } }
class Test{ public static void main(String arg []){ User user =new User(); try{ user.setAge(-20); }catch(Exception e){ System.out.println(e); } } }
浙公网安备 33010602011771号