public class ServiceException extends Exception {
public ServiceException() {
super("业务层异常!");
}
public ServiceException(String msg) {
super(msg);
}
}
在代码中就应用
public void validateSal(String job, double sal) throws ServiceException {
if("CLERK".equals(job) && (sal < 1000 || sal > 10000)) {
throw new ServiceException("软降工程师的工资不在正常范围内!");
} else if("SALESMAN".equals(job) && (sal < 5000 || sal > 20000)) {
throw new ServiceException("系统架构师的工资不在正常范围内!");
} else if("MANAGER".equals(job) && (sal < 800 || sal > 5000)) {
throw new ServiceException("软件测试师的工资不在正常范围内!");
}
}