NestedRuntimeException constructor
Abstract base class for runtime exceptions that can wrap other exceptions.
This class provides a foundation for creating exception hierarchies where exceptions can contain references to their underlying causes. It's particularly useful for framework-level exceptions that need to preserve the original error context while adding additional information.
Key Features:
- Maintains a chain of causation through nested exceptions
- Provides root cause analysis capabilities
- Supports exception type checking throughout the chain
- Offers formatted string representation with cause information
Example:
class DatabaseException extends NestedRuntimeException {
DatabaseException(String message, [Throwable? cause]) : super(message, cause);
}
// Usage with nested causes
try {
// Some database operation
} catch (e) {
throw DatabaseException('Failed to save user', e);
}
// Analyzing the exception chain
catch (e) {
if (e is NestedRuntimeException) {
print('Root cause: ${e.getRootCause()}');
print('Most specific: ${e.getMostSpecificCause()}');
}
}
Implementation
NestedRuntimeException([this.message, this.cause]);