NestedCheckedException constructor
Abstract base class for checked exceptions that can wrap other exceptions.
Similar to NestedRuntimeException, this class provides exception chaining capabilities for checked exceptions. It maintains the cause chain and provides utilities for analyzing the exception hierarchy.
Key Features:
- Exception chaining for checked exceptions
- Root cause analysis and traversal
- Type checking throughout the exception chain
- Consistent string representation with cause information
Example:
class ValidationException extends NestedCheckedException {
ValidationException(String message, [Throwable? cause]) : super(message, cause);
}
// Usage in validation scenarios
Future<void> validateUser(User user) async {
try {
await validateEmail(user.email);
} catch (e) {
throw ValidationException('User validation failed', e);
}
}
// Exception analysis
try {
await validateUser(user);
} catch (e) {
if (e is NestedCheckedException) {
final rootCause = e.getRootCause();
if (e.contains(Class<FormatException>())) {
print('Validation failed due to format error');
}
}
}
Implementation
NestedCheckedException(this.message, [this.cause]);