java中自定义一个异常类 在某些情况抛出自定的异常 ----------阻断程序

//=============定义异常类
package org.springblade.flow.engine.errorException;


/**
 * 自定义异常处理写入sap失败
 */
public class CallbackErrorException extends Exception{
    public CallbackErrorException(String detailMessage) {
        super(detailMessage);
    }
}

//============= 需要抛出异常的类
package org.springblade.flow.engine.listener.execution;
import lombok.SneakyThrows;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.springblade.desk.feign.IBusinessPartnerClient;
import org.springblade.flow.engine.errorException.CallbackErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * create by Dell on 2020/7/18
 */
@Component("businessPartnerExecutionListener")
public class BusinessPartnerExecutionListener implements ExecutionListener {

    @Autowired
    private IBusinessPartnerClient businessPartnerClient ;

    @SneakyThrows(CallbackErrorException.class)
    @Override
    public void notify(DelegateExecution execution) {
        String processInstanceId=execution.getProcessInstanceId();
        System.out.println("业务伙伴主数据processInstanceId=============="+processInstanceId);
        boolean msg=businessPartnerClient.businessPartnerCreate(processInstanceId);
        System.out.println("业务伙伴主数据msg=============="+msg);
        if(!msg) {
            throw new CallbackErrorException("写入sap失败,请从新发起申请");
        }
    }
}

 

posted @ 2020-08-01 11:53  红尘沙漏  阅读(398)  评论(0编辑  收藏  举报