Class OpenReflectException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
cloud.opencode.base.core.exception.OpenException
cloud.opencode.base.reflect.exception.OpenReflectException
- All Implemented Interfaces:
Serializable
Reflection Operation Exception (Unchecked)
反射操作异常(非受检)
Unchecked exception for reflection operations that wraps checked exceptions. Simplifies caller code by eliminating mandatory try-catch blocks.
用于反射操作的非受检异常,封装受检异常。 通过消除强制性的try-catch块来简化调用方代码。
Features | 主要功能:
- Unchecked exception wrapper - 非受检异常包装
- Target type and member tracking - 目标类型和成员追踪
- Factory methods for common errors - 常见错误的工厂方法
Usage Examples | 使用示例:
// Create with factory method
throw OpenReflectException.fieldNotFound(User.class, "name");
// Create with details
throw new OpenReflectException(User.class, "getName", "invoke", "Method not accessible");
Security | 安全性:
- Thread-safe: Yes (immutable after construction) - 线程安全: 是(构造后不可变)
- Null-safe: Yes (null target type is allowed) - 空值安全: 是(允许null目标类型)
- Since:
- JDK 25, opencode-base-reflect V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionOpenReflectException(Class<?> targetType, String memberName, String operation, String message) Creates an exception with target, member, operation and message 创建带目标、成员、操作和消息的异常OpenReflectException(Class<?> targetType, String memberName, String operation, String message, Throwable cause) Creates an exception with target, member, operation, message and cause 创建带目标、成员、操作、消息和原因的异常OpenReflectException(String message) Creates an exception with message 创建带消息的异常OpenReflectException(String message, Throwable cause) Creates an exception with message and cause 创建带消息和原因的异常 -
Method Summary
Modifier and TypeMethodDescriptionstatic OpenReflectExceptionannotationNotFound(Class<?> clazz, Class<?> annotationType) Creates an annotation not found exception 创建注解未找到异常static OpenReflectExceptionclassLoadFailed(String className, Throwable cause) Creates a class load failed exception 创建类加载失败异常static OpenReflectExceptionclassNotFound(String className) Creates a class not found exception 创建类未找到异常static OpenReflectExceptionconstructorNotFound(Class<?> clazz, Class<?>[] paramTypes) Creates a constructor not found exception 创建构造器未找到异常static OpenReflectExceptioncopyFailed(Class<?> sourceType, Class<?> targetType, Throwable cause) Creates a copy failed exception 创建复制失败异常static OpenReflectExceptionfieldAccessFailed(Class<?> clazz, String fieldName, Throwable cause) Creates a field access failed exception 创建字段访问失败异常static OpenReflectExceptionfieldNotFound(Class<?> clazz, String fieldName) Creates a field not found exception 创建字段未找到异常static OpenReflectExceptionillegalAccess(Class<?> clazz, String memberName, Throwable cause) Creates an illegal access exception 创建非法访问异常static OpenReflectExceptioninstantiationFailed(Class<?> clazz, Throwable cause) Creates an instantiation failed exception 创建实例化失败异常static OpenReflectExceptionlambdaParseFailed(String reason) Creates a lambda parse failed exception 创建Lambda解析失败异常Gets the member name 获取成员名称static OpenReflectExceptionmethodInvokeFailed(Class<?> clazz, String methodName, Throwable cause) Creates a method invoke failed exception 创建方法调用失败异常static OpenReflectExceptionmethodNotFound(Class<?> clazz, String methodName, Class<?>[] paramTypes) Creates a method not found exception 创建方法未找到异常Gets the operation type 获取操作类型static OpenReflectExceptionproxyCreationFailed(Class<?> interfaceType, Throwable cause) Creates a proxy creation failed exception 创建代理创建失败异常static OpenReflectExceptionrecordOperationFailed(Class<?> recordClass, String operation, Throwable cause) Creates a record operation failed exception 创建Record操作失败异常Class<?> Gets the target type 获取目标类型static OpenReflectExceptiontypeCastFailed(Class<?> targetType, Object value) Creates a type cast failed exception 创建类型转换失败异常Methods inherited from class OpenException
getComponent, getErrorCode, getMessage, getRawMessageMethods inherited from class Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
OpenReflectException
Creates an exception with message 创建带消息的异常- Parameters:
message- the error message | 错误消息
-
OpenReflectException
-
OpenReflectException
public OpenReflectException(Class<?> targetType, String memberName, String operation, String message) Creates an exception with target, member, operation and message 创建带目标、成员、操作和消息的异常- Parameters:
targetType- the target type | 目标类型memberName- the member name | 成员名称operation- the operation type | 操作类型message- the error message | 错误消息
-
OpenReflectException
public OpenReflectException(Class<?> targetType, String memberName, String operation, String message, Throwable cause) Creates an exception with target, member, operation, message and cause 创建带目标、成员、操作、消息和原因的异常- Parameters:
targetType- the target type | 目标类型memberName- the member name | 成员名称operation- the operation type | 操作类型message- the error message | 错误消息cause- the cause | 原因
-
-
Method Details
-
targetType
-
memberName
-
operation
-
fieldNotFound
Creates a field not found exception 创建字段未找到异常- Parameters:
clazz- the class | 类fieldName- the field name | 字段名- Returns:
- exception instance | 异常实例
-
fieldAccessFailed
public static OpenReflectException fieldAccessFailed(Class<?> clazz, String fieldName, Throwable cause) Creates a field access failed exception 创建字段访问失败异常- Parameters:
clazz- the class | 类fieldName- the field name | 字段名cause- the cause | 原因- Returns:
- exception instance | 异常实例
-
methodNotFound
public static OpenReflectException methodNotFound(Class<?> clazz, String methodName, Class<?>[] paramTypes) Creates a method not found exception 创建方法未找到异常- Parameters:
clazz- the class | 类methodName- the method name | 方法名paramTypes- the parameter types | 参数类型- Returns:
- exception instance | 异常实例
-
methodInvokeFailed
public static OpenReflectException methodInvokeFailed(Class<?> clazz, String methodName, Throwable cause) Creates a method invoke failed exception 创建方法调用失败异常- Parameters:
clazz- the class | 类methodName- the method name | 方法名cause- the cause | 原因- Returns:
- exception instance | 异常实例
-
constructorNotFound
Creates a constructor not found exception 创建构造器未找到异常- Parameters:
clazz- the class | 类paramTypes- the parameter types | 参数类型- Returns:
- exception instance | 异常实例
-
instantiationFailed
Creates an instantiation failed exception 创建实例化失败异常- Parameters:
clazz- the class | 类cause- the cause | 原因- Returns:
- exception instance | 异常实例
-
classNotFound
Creates a class not found exception 创建类未找到异常- Parameters:
className- the class name | 类名- Returns:
- exception instance | 异常实例
-
classLoadFailed
Creates a class load failed exception 创建类加载失败异常- Parameters:
className- the class name | 类名cause- the cause | 原因- Returns:
- exception instance | 异常实例
-
typeCastFailed
Creates a type cast failed exception 创建类型转换失败异常- Parameters:
targetType- the target type | 目标类型value- the value | 值- Returns:
- exception instance | 异常实例
-
copyFailed
public static OpenReflectException copyFailed(Class<?> sourceType, Class<?> targetType, Throwable cause) Creates a copy failed exception 创建复制失败异常- Parameters:
sourceType- the source type | 源类型targetType- the target type | 目标类型cause- the cause | 原因- Returns:
- exception instance | 异常实例
-
proxyCreationFailed
Creates a proxy creation failed exception 创建代理创建失败异常- Parameters:
interfaceType- the interface type | 接口类型cause- the cause | 原因- Returns:
- exception instance | 异常实例
-
annotationNotFound
Creates an annotation not found exception 创建注解未找到异常- Parameters:
clazz- the class | 类annotationType- the annotation type | 注解类型- Returns:
- exception instance | 异常实例
-
lambdaParseFailed
Creates a lambda parse failed exception 创建Lambda解析失败异常- Parameters:
reason- the reason | 原因- Returns:
- exception instance | 异常实例
-
recordOperationFailed
public static OpenReflectException recordOperationFailed(Class<?> recordClass, String operation, Throwable cause) Creates a record operation failed exception 创建Record操作失败异常- Parameters:
recordClass- the record class | Record类operation- the operation | 操作cause- the cause | 原因- Returns:
- exception instance | 异常实例
-
illegalAccess
public static OpenReflectException illegalAccess(Class<?> clazz, String memberName, Throwable cause) Creates an illegal access exception 创建非法访问异常- Parameters:
clazz- the class | 类memberName- the member name | 成员名cause- the cause | 原因- Returns:
- exception instance | 异常实例
-