NestedCheckedException class abstract
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');
}
}
}
- Inheritance
- Available extensions
Constructors
- NestedCheckedException(String? message, [Throwable? cause])
- Abstract base class for checked exceptions that can wrap other exceptions.
Properties
- cause → Throwable?
-
The underlying cause of this exception, if any.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- message → String?
-
The descriptive message for this exception.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- stackTrace → StackTrace?
-
The stack trace at the point where this error was first thrown.
no setterinherited
Methods
-
contains(
Class? exType) → bool - Checks if this exception or any exception in its cause chain is of the specified type.
-
getCause(
) → Throwable? -
The cause of this exception, if any.
override
-
getMessage(
) → String -
The message associated with this exception.
override
-
getMostSpecificCause(
) → Throwable - Returns the most specific cause of this exception.
-
getRootCause(
) → Throwable? - Returns the root cause of this exception by traversing the cause chain.
-
getStackTrace(
) → StackTrace -
The stack trace associated with this exception.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
printStackTrace(
[bool useErrorPrint = false]) → void -
Available on Error, provided by the ErrorExtensions extension
Prints the error along with its stack trace. -
printStackTrace(
[StackTrace? stacktrace, bool useErrorPrint = false]) → void -
Available on Exception, provided by the ExceptionExtensions extension
Prints the exception and optional StackTrace if available. -
printStackTrace(
[bool useErrorPrint = false]) → void -
Available on Throwable, provided by the ThrowableExtensions extension
Extension on Throwable to support printing stack traces in a unified way. -
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited