异常信息尝试获取
This commit is contained in:
@@ -3,6 +3,7 @@ package com.czg.utils;
|
|||||||
import cn.hutool.core.lang.func.Func0;
|
import cn.hutool.core.lang.func.Func0;
|
||||||
import cn.hutool.core.thread.ThreadUtil;
|
import cn.hutool.core.thread.ThreadUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.core.NestedExceptionUtils;
|
||||||
import org.springframework.transaction.support.TransactionSynchronization;
|
import org.springframework.transaction.support.TransactionSynchronization;
|
||||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||||
|
|
||||||
@@ -27,12 +28,17 @@ public class FunUtils {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void asyncSafeRunVoid(Runnable func, String... msg) {
|
||||||
|
ThreadUtil.execAsync(() -> safeRunVoid(func, msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void safeRunVoid(Runnable func, String... msg) {
|
public static void safeRunVoid(Runnable func, String... msg) {
|
||||||
try {
|
try {
|
||||||
func.run();
|
func.run();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("方法执行失败: {}", msg, e);
|
String message = NestedExceptionUtils.getMostSpecificCause(e).getMessage();
|
||||||
log.warn(msg.length > 0 ? msg[0] : "方法执行失败: {}", e.getMessage());
|
log.warn(msg.length > 0 ? msg[0] : "方法执行失败: {}", message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,10 +50,6 @@ public class FunUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void asyncSafeRunVoid(Runnable func, String... msg) {
|
|
||||||
ThreadUtil.execAsync(() -> safeRunVoid(func, msg));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在事务提交后执行方法
|
* 在事务提交后执行方法
|
||||||
* 异步 执行
|
* 异步 执行
|
||||||
|
|||||||
Reference in New Issue
Block a user