From bc998700bb8c47aa6ee6f3d7d4c1ea70176cf8c1 Mon Sep 17 00:00:00 2001 From: fengbaoheng Date: Thu, 26 Nov 2020 20:04:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=BF=90=E8=A1=8C=E6=97=B6?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=8C=85=E8=A3=85=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hutool/core/exceptions/ExceptionUtil.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/hutool-core/src/main/java/cn/hutool/core/exceptions/ExceptionUtil.java b/hutool-core/src/main/java/cn/hutool/core/exceptions/ExceptionUtil.java index f0cfafec6..8472b6ff5 100644 --- a/hutool-core/src/main/java/cn/hutool/core/exceptions/ExceptionUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/exceptions/ExceptionUtil.java @@ -48,7 +48,7 @@ public class ExceptionUtil { /** * 使用运行时异常包装编译异常
* - * 如果 + * 如果传入参数已经是运行时异常,则直接返回,不再额外包装 * * @param throwable 异常 * @return 运行时异常 @@ -60,6 +60,16 @@ public class ExceptionUtil { return new RuntimeException(throwable); } + /** + * 将指定的消息包装为运行时异常 + * @param message 异常消息 + * @return 运行时异常 + * @since 5.5.2 + */ + public static RuntimeException wrapRuntime(String message){ + return new RuntimeException(message); + } + /** * 包装一个异常 * @@ -93,6 +103,15 @@ public class ExceptionUtil { throw new UndeclaredThrowableException(throwable); } + /** + * 将消息包装为运行时异常并抛出 + * @param message 异常消息 + * @since 5.5.2 + */ + public static void wrapRuntimeAndThrow(String message){ + throw new RuntimeException(message); + } + /** * 剥离反射引发的InvocationTargetException、UndeclaredThrowableException中间异常,返回业务本身的异常 *