如何解决将子类的自定义异常从 for each 循环抛出到父类
Class ProductServiceClass {
Try {
Product.callCustbusinessLogic();
} catch (CustomStatusException cse) {
jsonresponse.setError(cse.getError);
}
}
Class Product throws CustomStatusException,Exception {
public Customer callCustbusinessLogic() {
for (type Customerlist: customer) {
Try {
List < Customer > customerlist = new ArrayList < > ();
return customerlist.add(CustomerCheck.businessLogic());
}
Catch() {
// stack overflow question,how to throw the "Not a valid customer" occurred
// in CustomerCheck class to ProductServiceClass
}
}
}
}
Class CustomerCheck throws CustomStatusException,Exception {
public Customer businessLogic() {
try {
// business logic
return customer;
} catch (Exception e) {
CustomStatusException cse = new CustomStatusException();
cse.setError("Not a valid customer");
throw cse;
}
}
}
ProductServiceClass 调用 Product 类,Product 类调用 CustomerCheck。异常发生在 CustomerCheck 类中,因此需要将该特定客户对象的自定义异常发送到父类 ProductServiceClass,但是 b/c 在 Product 类中的 customerlist 的每个循环无法将自定义异常发送到除标准运行时异常外的父类。
即使 Product 类中有一个 for each ,你能帮忙如何将 CustomStatusException 抛出到 ProductServiceClass 吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。