diff --git a/sdk/lib/_internal/wasm/lib/sync_star_patch.dart b/sdk/lib/_internal/wasm/lib/sync_star_patch.dart index 9f73b7ea83b..ece864f78b5 100644 --- a/sdk/lib/_internal/wasm/lib/sync_star_patch.dart +++ b/sdk/lib/_internal/wasm/lib/sync_star_patch.dart @@ -139,17 +139,22 @@ class _SyncStarIterator implements Iterator { // Case: yield* some_iterator. final iterable = _yieldStarIterable; if (iterable != null) { + _yieldStarIterable = null; + _current = null; if (iterable is _SyncStarIterable) { // We got a recursive yield* of sync* function. Instead of creating // a new iterator we replace our current _state (remembering the // current _state for later resumption). _state = _SuspendState(iterable, _state).._iterator = this; } else { - _yieldStarIterator = iterable.iterator; + try { + _yieldStarIterator = iterable.iterator; + } catch (exception, stackTrace) { + pendingException = exception; + pendingStackTrace = stackTrace; + } } - _yieldStarIterable = null; - _current = null; - // Fetch the next item. + // Fetch the next item or continue with exception. continue; }