package mistake; class NomoneyException extends Exception{ public NomoneyException(String message){ super(message);//调用Exception的一个参数构造函数 } } public class selfmistake { public static void main(String[] args) { int money=9; try { chifan(money); } catch (NomoneyException e) { e.printStackTrace(); System.out.println("快回去带钱!!"); } } public static void chifan(int money) throws NomoneyException{ if(money<10){ throw new NomoneyException("没钱别吃饭"); }else{ System.out.println("吃地沟油木桶饭!!"); } } }