public class ExceptionSelfThrows { public static void main(String[] args) { try { showSalary("王先生",25000); showSalary("張小姐",50000); } catch (IllegalArgumentException e){ System.out.println("例外內容:"+ e.getMessage()); } } private static void showSalary(String name, int money)throws IllegalArgumentException { if (money >= 22000 && money <= 33000 ) System.out.println("員工 "+ name + "\t底薪:"+ money); else throw new IllegalArgumentException("呼叫引數錯誤"); } }執行結果
沒有留言:
張貼留言