Class OpenMatchException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
cloud.opencode.base.core.exception.OpenException
cloud.opencode.base.functional.exception.OpenFunctionalException
cloud.opencode.base.functional.exception.OpenMatchException
- All Implemented Interfaces:
OpenExceptionMeta, Serializable
OpenMatchException - Exception for pattern matching failures
OpenMatchException - 模式匹配失败的异常
Thrown when pattern matching fails to find a matching case for the input value.
当模式匹配无法为输入值找到匹配的分支时抛出。
Features | 主要功能:
- Captures unmatched value - 捕获未匹配的值
- Supports sealed type exhaustiveness errors - 支持密封类型完备性错误
- Factory methods for common scenarios - 常见场景的工厂方法
Usage Examples | 使用示例:
// Thrown when no pattern matches
throw OpenMatchException.noMatch(value);
// Thrown for non-exhaustive sealed type matching
throw OpenMatchException.exhaustive(value, Shape.class);
// Access unmatched value
try {
OpenMatch.of(value).orElseThrow();
} catch (OpenMatchException e) {
Object unmatched = e.unmatchedValue();
}
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是 (不可变)
- Serializable: Yes - 可序列化: 是
- Since:
- JDK 25, opencode-base-functional V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Field Summary
Fields inherited from class OpenFunctionalException
COMPONENT -
Constructor Summary
ConstructorsConstructorDescriptionOpenMatchException(String message) Create exception with message 创建带消息的异常OpenMatchException(String message, Object unmatchedValue) Create exception with message and unmatched value 创建带消息和未匹配值的异常OpenMatchException(String errorCode, String message, Object unmatchedValue) Create exception with error code, message and unmatched value 创建带错误码、消息和未匹配值的异常 -
Method Summary
Modifier and TypeMethodDescriptionstatic OpenMatchExceptionexhaustive(Object value, Class<?> sealedType) Create exception for non-exhaustive sealed type matching 为密封类型非完备匹配创建异常static OpenMatchExceptionguardFailed(Object value) Create exception for guard condition failure 为守卫条件失败创建异常static OpenMatchExceptionCreate exception for no matching pattern 为没有匹配模式创建异常static OpenMatchExceptiontypeMismatch(Object value, Class<?> expectedType) Create exception for type mismatch 为类型不匹配创建异常Get the value that was not matched 获取未匹配的值Methods inherited from class OpenFunctionalException
computationFailed, computationFailed, filterFailed, invalidState, mappingFailed, noValueMethods inherited from class OpenException
getComponent, getErrorCode, getMessage, getRawMessageMethods inherited from class Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface OpenExceptionMeta
getMetaPrefix
-
Constructor Details
-
OpenMatchException
Create exception with message 创建带消息的异常- Parameters:
message- error message | 错误消息
-
OpenMatchException
-
OpenMatchException
-
-
Method Details
-
unmatchedValue
Get the value that was not matched 获取未匹配的值- Returns:
- the unmatched value, may be null | 未匹配的值,可能为 null
-
noMatch
Create exception for no matching pattern 为没有匹配模式创建异常- Parameters:
value- the value that was not matched | 未匹配的值- Returns:
- exception instance | 异常实例
-
exhaustive
Create exception for non-exhaustive sealed type matching 为密封类型非完备匹配创建异常- Parameters:
value- the value that was not matched | 未匹配的值sealedType- the sealed type being matched | 被匹配的密封类型- Returns:
- exception instance | 异常实例
-
guardFailed
Create exception for guard condition failure 为守卫条件失败创建异常- Parameters:
value- the value that failed the guard | 守卫失败的值- Returns:
- exception instance | 异常实例
-
typeMismatch
Create exception for type mismatch 为类型不匹配创建异常- Parameters:
value- the actual value | 实际值expectedType- the expected type | 期望的类型- Returns:
- exception instance | 异常实例
-