Java自定义异常

public class BankStatementRepeatException extends Exception {

public BankStatementRepeatException(String msg){
super(msg);
}

}


public void method()  throws BankStatementRepeatException {

boolean judgeBankAccountflag= false;

if(!judgeBankAccountflag){ //false表示重复

throw new BankAccountRepeatException("银行账户:【"+xxxx+"】重复!");

}

}


--------------------------------------------------------------------------


class 自定义异常名 extends Exceprion {

public 自定义异常名 (String message) {

super (message);

}

}


try{

} catch (BankAccountRepeatException repeatException) {

repeatException.getMessage() //输出异常的信息

}




你可能感兴趣的:(工作日常)