```class Foo { val seq: Sequence<Bar> = ...
# getting-started
Copy code
class Foo {
    val seq: Sequence<Bar> = //...
    fun process() {
        for (elem in seq) {
            // do something with elem, 
            // but maybe throw an exception
is it sound to call
again if an exception is thrown? will the sequence continue from the element immediately after the element for which the exception was thrown?
Yes. As long as the exception wasn't thrown by the sequence itself, it is in valid state even if an exception appeared somewhere else (and it will continue from the next element which wasn't yet read).
The element read at the time the exception happened is lost though (it was removed from the sequence by the for loop), so you have to recover it yourself.
If your goal is to communicate to the caller whether they should retry the operation or not, there is probably a better way to do it, though. What's your objective?
I had the (probably bad) idea of wrapping that
function in a loop that keeps retrying the function until
is exhausted. the
block of the wrapping function does something with the caught exceptions.
now that I think about it, if I do end up doing this, the iteration should be in the wrapping function, and
should take the next yielded value
…which basically is an event loop