fuint-framework/fuint-util/src/main/java/com/fuint/exception/Exceptions.java
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
package com.fuint.exception;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
* 关于异常的工具类.
*
* 参考了guava的Throwables。
*
* @author fsq
* @version $Id: Exceptions.java
*/
public class Exceptions {
/**
* 将CheckedException转换为UncheckedException.
*/
public static RuntimeException unchecked(Throwable ex) {
if (ex instanceof RuntimeException) {
return (RuntimeException) ex;
} else {
return new RuntimeException(ex);
}
}
/**
* 将ErrorStack转化为String.
*/
public static String getStackTraceAsString(Throwable ex) {
StringWriter stringWriter = new StringWriter();
ex.printStackTrace(new PrintWriter(stringWriter));
return stringWriter.toString();
}
/**
* 获取组合本异常信息与底层异常信息的异常描述, 适用于本异常为统一包装异常类,底层异常才是根本原因的情况。
*/
public static String getErrorMessageWithNestedException(Throwable ex) {
Throwable nestedException = ex.getCause();
return new StringBuilder().append(ex.getMessage()).append(" nested exception is ")
.append(nestedException.getClass().getName()).append(":")
.append(nestedException.getMessage()).toString();
}
/**
* 获取异常的Root Cause.
*/
public static Throwable getRootCause(Throwable ex) {
Throwable cause;
while ((cause = ex.getCause()) != null) {
ex = cause;
}
return ex;
}
/**
* 判断异常是否由某些底层的异常引起.
*/
public static boolean isCausedBy(Exception ex, Class<? extends Exception>... causeExceptionClasses) {
后面还有 12 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。