}
*/
public void save(float money){ this.money += money; } /**
* 取钱
* @param money */
public void draw(float money) throws MyException{ try {
if(this.money < money){
throw new MyException("余额不足"); }
this.money -= money; } catch (MyException e) {
e.reportError("余额不足"); } }
package shiyan5;
public class shiyan5 {
public static void main(String[] args) throws MyException { bank bank = new bank(); bank.save(100.0f); bank.draw(200.0f); } }
运行结果是: