You can not. As soon as an exception occurs, the state of the source enumerator is confused. If you cannot enter the original counter to โlock inโ its state, you cannot force it to continue to create values.
You can, however, make the whole process โstoppedโ after an exception, but you need to go below the level and work with IEnumerator<T> :
let takeUntilError (sq: seq<_>) = seq { use enm = sq.GetEnumerator() let next () = try enm.MoveNext() with _ -> false let cur () = try Some enm.Current with _ -> None while next() do match cur() with | Some c -> yield c | None -> () } mySeq |> takeUntilError |> Seq.iter (printf "%d")
source share