can some explain me the following? ```import kotli...
# coroutines
e
can some explain me the following?
Copy code
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancelChildren
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import sun.misc.Signal

suspend fun main() {
    withContext(Dispatchers.Default) {
        Signal.handle(Signal("INT")) {signal ->
            println("RECEIVED ${signal.name}")
            this.coroutineContext.cancelChildren()
        }

        launch {
            withContext(Dispatchers.Default) {
                launch {
                    while (true) {
                        try {
                            println("foo")
                            // delay(2000) // if I put delay here, it fails with an infinite loop on SIGINT
                        } catch (e: Exception) {
                            println("error: ${e.message}")
                        }
                        delay(2000) // if I put delay here outside try-catch, no problem on SIGINT
                    }
                }
            }
        }
    }
    println("finished")
}
why does
delay
within a
try-catch
causes an infinite loop with errors?
e
don't catch Exception. you have intercepted
CancellationException
which breaks
so the scope is cancelled state, but keeps retrying to delay, which fails because the scope is cancelled, ad infinitum
🙏 1