use of io.seata.saga.statelang.domain.TaskState.ExceptionMatch in project seata by seata.
the class EngineUtils method handleException.
/**
* Handle exceptions while ServiceTask or ScriptTask Executing
*
* @param context
* @param state
* @param e
*/
public static void handleException(ProcessContext context, AbstractTaskState state, Throwable e) {
List<ExceptionMatch> catches = state.getCatches();
if (CollectionUtils.isNotEmpty(catches)) {
for (TaskState.ExceptionMatch exceptionMatch : catches) {
List<String> exceptions = exceptionMatch.getExceptions();
List<Class<? extends Exception>> exceptionClasses = exceptionMatch.getExceptionClasses();
if (CollectionUtils.isNotEmpty(exceptions)) {
if (exceptionClasses == null) {
synchronized (exceptionMatch) {
exceptionClasses = exceptionMatch.getExceptionClasses();
if (exceptionClasses == null) {
exceptionClasses = new ArrayList<>(exceptions.size());
for (String expStr : exceptions) {
Class<? extends Exception> expClass = null;
try {
expClass = (Class<? extends Exception>) ScriptTaskStateHandler.class.getClassLoader().loadClass(expStr);
} catch (Exception e1) {
LOGGER.warn("Cannot Load Exception Class by getClass().getClassLoader()", e1);
try {
expClass = (Class<? extends Exception>) Thread.currentThread().getContextClassLoader().loadClass(expStr);
} catch (Exception e2) {
LOGGER.warn("Cannot Load Exception Class by Thread.currentThread()" + ".getContextClassLoader()", e2);
}
}
if (expClass != null) {
exceptionClasses.add(expClass);
}
}
exceptionMatch.setExceptionClasses(exceptionClasses);
}
}
}
for (Class<? extends Exception> expClass : exceptionClasses) {
if (expClass.isAssignableFrom(e.getClass())) {
((HierarchicalProcessContext) context).setVariableLocally(DomainConstants.VAR_NAME_CURRENT_EXCEPTION_ROUTE, exceptionMatch.getNext());
return;
}
}
}
}
}
LOGGER.error("Task execution failed and no catches configured");
((HierarchicalProcessContext) context).setVariableLocally(DomainConstants.VAR_NAME_IS_EXCEPTION_NOT_CATCH, true);
}
use of io.seata.saga.statelang.domain.TaskState.ExceptionMatch in project seata by seata.
the class AbstractTaskStateParser method parseCatch.
protected List<ExceptionMatch> parseCatch(List<Object> catchList) {
List<ExceptionMatch> exceptionMatchList = new ArrayList<>(catchList.size());
for (Object exceptionMatchObj : catchList) {
Map<String, Object> exceptionMatchMap = (Map<String, Object>) exceptionMatchObj;
ExceptionMatchImpl exceptionMatch = new ExceptionMatchImpl();
exceptionMatch.setExceptions((List<String>) exceptionMatchMap.get("Exceptions"));
exceptionMatch.setNext((String) exceptionMatchMap.get("Next"));
exceptionMatchList.add(exceptionMatch);
}
return exceptionMatchList;
}
Aggregations