import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.ArrayUtils;
/**
* 异常处理工具类
*
*/
public final class HandleExceptionUtils {
private HandleExceptionUtils(){}
/**
* 异常处理方法
*
* @param throwable 异常
* @return
*/
public static String handleException(Throwable throwable) {
JSONObject errorJson = new JSONObject();
StackTraceElement[] stackTraceArray = throwable.getStackTrace();
errorJson.put("exceptionType", throwable.getClass().getName());
errorJson.put("exceptionMessage", throwable.getLocalizedMessage());
if (ArrayUtils.isNotEmpty(stackTraceArray)) {
int maxSize = Math.min(stackTraceArray.length, 20);
JSONArray array = new JSONArray();
for (int i = 0; i < maxSize; i++) {
StackTraceElement stackTraceElement = stackTraceArray[i];