Class OpenCollectionException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
cloud.opencode.base.core.exception.OpenException
cloud.opencode.base.collections.exception.OpenCollectionException
- All Implemented Interfaces:
OpenExceptionMeta, Serializable
OpenCollectionException - Exception for collection operations
OpenCollectionException - 集合操作异常
This exception is thrown when collection operations fail or encounter invalid states.
Extends OpenException for unified exception handling across OpenCode components.
当集合操作失败或遇到无效状态时抛出此异常。继承 OpenException 以实现 OpenCode 组件间的统一异常处理。
Features | 主要功能:
- Extends OpenException with component="Collections" - 继承 OpenException,组件名="Collections"
- Wraps underlying exceptions - 包装底层异常
- Provides meaningful error messages - 提供有意义的错误消息
- Supports exception chaining - 支持异常链
- Factory methods for common scenarios - 常见场景的工厂方法
Usage Examples | 使用示例:
// Throw with message - 带消息抛出
throw new OpenCollectionException("Collection is empty");
// Throw with cause - 带原因抛出
throw new OpenCollectionException("Operation failed", cause);
// Factory methods - 工厂方法
throw OpenCollectionException.emptyCollection("list");
throw OpenCollectionException.indexOutOfBounds(10, 5);
throw OpenCollectionException.duplicateKey("key1");
// Catch with unified OpenException - 使用统一 OpenException 捕获
try { ... } catch (OpenException e) { // catches all OpenCode exceptions }
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Serializable: Yes - 可序列化: 是
- Since:
- JDK 25, opencode-base-collections V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionOpenCollectionException(String message) Constructs a new exception with the specified message.OpenCollectionException(String message, Throwable cause) Constructs a new exception with the specified message and cause.OpenCollectionException(Throwable cause) Constructs a new exception with the specified cause. -
Method Summary
Modifier and TypeMethodDescriptionstatic OpenCollectionExceptionduplicateKey(Object key) Create exception for duplicate key.static OpenCollectionExceptionduplicateValue(Object value) Create exception for duplicate value.static OpenCollectionExceptionelementNotFound(Object element) Create exception for element not found.static OpenCollectionExceptionemptyCollection(String collectionType) Create exception for empty collection.static OpenCollectionExceptionillegalCapacity(int capacity) Create exception for illegal capacity.static OpenCollectionExceptionCreate exception for immutable collection modification.static OpenCollectionExceptionindexOutOfBounds(int index, int size) Create exception for index out of bounds.static OpenCollectionExceptionkeyNotFound(Object key) Create exception for key not found.static OpenCollectionExceptionmultipleElementsFound(int count) Create exception for multiple elements found when expecting one.static OpenCollectionExceptionnegativeSize(int size) Create exception for negative size.static OpenCollectionExceptionCreate exception for null element.static OpenCollectionExceptionnullKey()Create exception for null key.static OpenCollectionExceptionCreate exception for null value.static OpenCollectionExceptionunsupportedOperation(String operation) Create exception for unsupported operation.Methods 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
-
OpenCollectionException
Constructs a new exception with the specified message. 构造带指定消息的新异常。- Parameters:
message- the detail message | 详细消息
-
OpenCollectionException
-
OpenCollectionException
Constructs a new exception with the specified cause. 构造带指定原因的新异常。- Parameters:
cause- the cause | 原因
-
-
Method Details
-
emptyCollection
Create exception for empty collection. 创建空集合异常。- Parameters:
collectionType- the type of collection | 集合类型- Returns:
- new exception | 新异常
-
indexOutOfBounds
Create exception for index out of bounds. 创建索引越界异常。- Parameters:
index- the invalid index | 无效索引size- the collection size | 集合大小- Returns:
- new exception | 新异常
-
duplicateKey
Create exception for duplicate key. 创建重复键异常。- Parameters:
key- the duplicate key | 重复的键- Returns:
- new exception | 新异常
-
duplicateValue
Create exception for duplicate value. 创建重复值异常。- Parameters:
value- the duplicate value | 重复的值- Returns:
- new exception | 新异常
-
nullElement
Create exception for null element. 创建空元素异常。- Returns:
- new exception | 新异常
-
nullKey
Create exception for null key. 创建空键异常。- Returns:
- new exception | 新异常
-
nullValue
Create exception for null value. 创建空值异常。- Returns:
- new exception | 新异常
-
immutableCollection
Create exception for immutable collection modification. 创建不可变集合修改异常。- Returns:
- new exception | 新异常
-
elementNotFound
Create exception for element not found. 创建元素未找到异常。- Parameters:
element- the element | 元素- Returns:
- new exception | 新异常
-
keyNotFound
Create exception for key not found. 创建键未找到异常。- Parameters:
key- the key | 键- Returns:
- new exception | 新异常
-
illegalCapacity
Create exception for illegal capacity. 创建非法容量异常。- Parameters:
capacity- the illegal capacity | 非法容量- Returns:
- new exception | 新异常
-
multipleElementsFound
Create exception for multiple elements found when expecting one. 创建期望单个元素但找到多个异常。- Parameters:
count- the actual count | 实际数量- Returns:
- new exception | 新异常
-
negativeSize
Create exception for negative size. 创建负数大小异常。- Parameters:
size- the negative size | 负数大小- Returns:
- new exception | 新异常
-
unsupportedOperation
Create exception for unsupported operation. 创建不支持的操作异常。- Parameters:
operation- the operation name | 操作名称- Returns:
- new exception | 新异常
-