本文主要是介绍一句话调用,简化抛出异常代码,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
下面的业务异常抛出代码,写的真好。通过一个变量判断,然后抛出异常,调用时代码很简洁。
PredicateUtil.testMarketToUpgrade(isUpgrade);
package com.myfun.utils;import com.myfun.framework.exception.UpgradeGuideException;public class PredicateUtil {public static void testMarketToUpgrade(boolean isMarket) {if (isMarket) {throw new UpgradeGuideException();}}
}
import com.myfun.repository.support.constant.Const;import java.util.HashMap;/*** @author guohao* @date 2018-06-02 10:54*/
public class UpgradeGuideException extends BusinessException {public UpgradeGuideException() {this("此功能仅对O2O会员开放", Const.ResponseErrorCode.UPGRADE_GUIDE);}public UpgradeGuideException(String message, String errCode) {super(message, errCode);}public UpgradeGuideException(HashMap<String, Object> extMap) {this();this.setExtMap(extMap);}
}
这篇关于一句话调用,简化抛出异常代码的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!