All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.boot.error.ErrorUtil Maven / Gradle / Ivy

The newest version!
package org.zodiac.boot.error;

import java.util.Date;

import org.zodiac.log.model.entity.LogError;
import org.zodiac.sdk.toolkit.util.ExceptionUtil;
import org.zodiac.sdk.toolkit.util.lang.ObjUtil;

/**
 * 异常工具类。
 *
 */
public class ErrorUtil {

    /**
     * 初始化异常信息。
     *
     * @param error 异常
     * @param event 异常事件封装
     */
    public static void initErrorInfo(Throwable error, LogError event) {
        /*堆栈信息。*/
        event.setStackTrace(ExceptionUtil.stackTrace(error));
        event.setExceptionName(error.getClass().getName());
        event.setMessage(error.getMessage());
        event.setCreateTime(new Date());
        StackTraceElement[] elements = error.getStackTrace();
        if (ObjUtil.isNotEmptyObject(elements)) {
            /*报错的类信息。*/
            StackTraceElement element = elements[0];
            event.setMethodClass(element.getClassName());
            event.setFileName(element.getFileName());
            event.setMethodName(element.getMethodName());
            event.setLineNumber(element.getLineNumber());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy