Future<T>.error constructor
- Object error, [
- StackTrace? stackTrace
Creates a future that completes with an error.
The created future will be completed with an error in a future microtask. This allows enough time for someone to add an error handler on the future. If an error handler isn't added before the future completes, the error will be considered unhandled.
Use Completer to create a future and complete it later.
Example:
Future<int> getFuture() {
return Future.error(Exception('Issue'));
}
final error = await getFuture(); // Throws.
Implementation
factory Future.error(Object error, [StackTrace? stackTrace]) {
AsyncError(:error, :stackTrace) = _interceptUserError(error, stackTrace);
return new _Future<T>.immediateError(error, stackTrace);
}