refactor: 重构 MultiTypesException.ExceptionType 接口
- 将 `ExceptionType` 中的工厂方法抽取到 `ExceptionFactory` 中 - 更新相关文档注释
This commit is contained in:
parent
8828b12c78
commit
577b73874b
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package xyz.zhouxy.plusone.commons.exception;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* 异常工厂
|
||||
*
|
||||
* @author ZhouXY
|
||||
*/
|
||||
public interface ExceptionFactory<X extends Exception> {
|
||||
/**
|
||||
* 创建异常
|
||||
*
|
||||
* @return 异常对象
|
||||
*/
|
||||
@Nonnull
|
||||
X create();
|
||||
|
||||
/**
|
||||
* 使用指定 {@code message} 创建异常
|
||||
*
|
||||
* @param message 异常信息
|
||||
* @return 异常对象
|
||||
*/
|
||||
@Nonnull
|
||||
X create(String message);
|
||||
|
||||
/**
|
||||
* 使用指定 {@code cause} 创建异常
|
||||
*
|
||||
* @param cause 包装的异常
|
||||
* @return 异常对象
|
||||
*/
|
||||
@Nonnull
|
||||
X create(Throwable cause);
|
||||
|
||||
/**
|
||||
* 使用指定 {@code message} 和 {@code cause} 创建异常
|
||||
*
|
||||
* @param message 异常信息
|
||||
* @param cause 包装的异常
|
||||
* @return 异常对象
|
||||
*/
|
||||
@Nonnull
|
||||
X create(String message, Throwable cause);
|
||||
}
|
@ -29,7 +29,8 @@ import xyz.zhouxy.plusone.commons.base.IWithCode;
|
||||
* 异常实现 {@link MultiTypesException} 的 {@link #getType} 方法,返回对应的场景类型。
|
||||
*
|
||||
* <p>
|
||||
* 表示场景类型的枚举实现 {@link ExceptionType},其中的工厂方法用于创建对应类型的异常。
|
||||
* 表示场景类型的枚举实现 {@link ExceptionType},各个枚举值本身就是该场景的异常的工厂实例,
|
||||
* 使用其中的工厂方法用于创建对应类型的异常。
|
||||
*
|
||||
* <pre>
|
||||
* public final class LoginException
|
||||
@ -120,7 +121,9 @@ import xyz.zhouxy.plusone.commons.base.IWithCode;
|
||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public interface MultiTypesException<E extends Exception, T extends MultiTypesException.ExceptionType<E>> {
|
||||
public interface MultiTypesException<
|
||||
X extends Exception,
|
||||
T extends MultiTypesException.ExceptionType<X>> {
|
||||
|
||||
/**
|
||||
* 异常类型
|
||||
@ -142,48 +145,13 @@ public interface MultiTypesException<E extends Exception, T extends MultiTypesEx
|
||||
/**
|
||||
* 异常类型
|
||||
*/
|
||||
public static interface ExceptionType<E extends Exception> extends IWithCode<String> {
|
||||
public static interface ExceptionType<X extends Exception>
|
||||
extends IWithCode<String>, ExceptionFactory<X> {
|
||||
|
||||
/**
|
||||
* 默认异常信息
|
||||
*/
|
||||
String getDefaultMessage();
|
||||
|
||||
/**
|
||||
* 创建异常
|
||||
*
|
||||
* @return 异常对象
|
||||
*/
|
||||
@Nonnull
|
||||
E create();
|
||||
|
||||
/**
|
||||
* 使用指定 {@code message} 创建异常
|
||||
*
|
||||
* @param message 异常信息
|
||||
* @return 异常对象
|
||||
*/
|
||||
@Nonnull
|
||||
E create(String message);
|
||||
|
||||
/**
|
||||
* 使用指定 {@code cause} 创建异常
|
||||
*
|
||||
* @param cause 包装的异常
|
||||
* @return 异常对象
|
||||
*/
|
||||
@Nonnull
|
||||
E create(Throwable cause);
|
||||
|
||||
/**
|
||||
* 使用指定 {@code message} 和 {@code cause} 创建异常
|
||||
*
|
||||
* @param message 异常信息
|
||||
* @param cause 包装的异常
|
||||
* @return 异常对象
|
||||
*/
|
||||
@Nonnull
|
||||
E create(String message, Throwable cause);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,8 @@
|
||||
* 异常实现 {@link MultiTypesException} 的 {@link MultiTypesException#getType} 方法,返回对应的场景类型。
|
||||
*
|
||||
* <p>
|
||||
* 表示场景类型的枚举实现 {@link MultiTypesException.ExceptionType},其中的工厂方法用于创建对应类型的异常。
|
||||
* 表示场景类型的枚举实现 {@link MultiTypesException.ExceptionType},各个枚举值本身就是该场景的异常的工厂实例,
|
||||
* 使用其中的工厂方法用于创建对应类型的异常。
|
||||
*
|
||||
* <pre>
|
||||
* public final class LoginException
|
||||
|
Loading…
x
Reference in New Issue
Block a user