/** * @author tangxi.zq * @apiNote 抛出异常 */ public class ExceptionThrow { public static void main(String[]args) { try{ System.out.println(tax(2000, 0.1)); System.out.println(tax(-200, 0.1)); System.out.println(tax(2000, -0.1)); System.out.println(tax(20000,0.2)); } catch (IllegalArgumentException e) { e.printStackTrace(); } finally { System.out.println("End."); } } static double tax(int salary, double rate) { if(salary < 0 || rate < 0) { throw new IllegalArgumentException(); } return salary * rate; } }
666
你好,如何能让
System.out.println(tax(20000,0.2));
也执行了呢? 这个貌似是抛出异常,代码就不运行了
Sign in to make a reply
用户5527594890