我们是否有可能在 drools 中抛出自定义异常?
所以,我有一些规则,需要用重要数据抛出自定义异常。
流口水规则:
import com.statest.aifmd.etl.validator.data.ValidationException
rule "Linking Rule"
when
$dictionary: Dictionary()
$fileName: String()
then
queryFundMasterTable("String", $dictionary, $fileName);
end
function void queryFundMasterTable(String sourceFieldName Dictionary dictionary, String fileName) {
String result = dictionary.findRecord(sourceFieldName);
if ((result == null) || result.isEmpty()) {
throw new ValidationException(new ValidationMessage(fileName, Level.WARNING));
}
}
Java:
public void process(ExtractRow row, ValidRecord validRecord, String extractFilename) throws ValidationException {
session.execute(Arrays.asList(new Object[] { filename, dictionary}));
}
最佳答案
你可以做到。您必须 try catch fireAllRules 调用,并期待 org.drools.runtime.rule.ConsequenceException 包装您的自定义异常。
但这是一种相当粗俗的退出引擎的方式,并且它永远不应该被用来表示正常甚至不寻常的控制流。但是,如果您的 ValidationException 将导致正常关闭,那么就可以了。
关于java - 在 (Drools) 中抛出自定义异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20348887/