将子类的自定义异常从 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 (将#修改为@)