浏览代码

添加运行时异常包装方法

fengbaoheng 5 年之前
父节点
当前提交
bc998700bb
共有 1 个文件被更改,包括 20 次插入1 次删除
  1. 20 1
      hutool-core/src/main/java/cn/hutool/core/exceptions/ExceptionUtil.java

+ 20 - 1
hutool-core/src/main/java/cn/hutool/core/exceptions/ExceptionUtil.java

@@ -48,7 +48,7 @@ public class ExceptionUtil {
 	/**
 	 * 使用运行时异常包装编译异常<br>
 	 * 
-	 * 如果
+	 * 如果传入参数已经是运行时异常,则直接返回,不再额外包装
 	 * 
 	 * @param throwable 异常
 	 * @return 运行时异常
@@ -61,6 +61,16 @@ public class ExceptionUtil {
 	}
 
 	/**
+	 * 将指定的消息包装为运行时异常
+	 * @param message 异常消息
+	 * @return 运行时异常
+	 * @since 5.5.2
+	 */
+	public static RuntimeException wrapRuntime(String message){
+		return new RuntimeException(message);
+	}
+
+	/**
 	 * 包装一个异常
 	 *
 	 * @param <T> 被包装的异常类型
@@ -94,6 +104,15 @@ public class ExceptionUtil {
 	}
 
 	/**
+	 * 将消息包装为运行时异常并抛出
+	 * @param message 异常消息
+	 * @since 5.5.2
+	 */
+	public static void wrapRuntimeAndThrow(String message){
+		throw new RuntimeException(message);
+	}
+
+	/**
 	 * 剥离反射引发的InvocationTargetException、UndeclaredThrowableException中间异常,返回业务本身的异常
 	 * 
 	 * @param wrapped 包装的异常