mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
不使用Apache-Commons-Lang3的获取最尾端异常,采用递归方式
This commit is contained in:
parent
d25421bafd
commit
401b800a8c
@ -416,16 +416,17 @@ public class ExceptionUtil {
|
|||||||
* 此方法通过调用{@link Throwable#getCause()} 直到没有cause为止,如果异常本身没有cause,返回异常本身<br>
|
* 此方法通过调用{@link Throwable#getCause()} 直到没有cause为止,如果异常本身没有cause,返回异常本身<br>
|
||||||
* 传入null返回也为null
|
* 传入null返回也为null
|
||||||
*
|
*
|
||||||
* <p>
|
|
||||||
* 此方法来自Apache-Commons-Lang3
|
|
||||||
* </p>
|
|
||||||
*
|
*
|
||||||
* @param throwable 异常对象,可能为null
|
* @param throwable 异常对象,可能为null
|
||||||
* @return 最尾端异常,传入null参数返回也为null
|
* @return 最尾端异常,传入null参数返回也为null
|
||||||
*/
|
*/
|
||||||
public static Throwable getRootCause(final Throwable throwable) {
|
public static Throwable getRootCause(final Throwable throwable) {
|
||||||
final List<Throwable> list = getThrowableList(throwable);
|
Throwable cause = throwable.getCause();
|
||||||
return list.size() < 1 ? null : list.get(list.size() - 1);
|
if (cause != null) {
|
||||||
|
return getRootCause(cause);
|
||||||
|
}else{
|
||||||
|
return throwable;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user