<lambda>null1// This file was automatically generated from exception-handling.md by Knit tool. Do not edit. 2 package kotlinx.coroutines.guide.exampleSupervision01 3 4 import kotlinx.coroutines.* 5 6 fun main() = runBlocking { 7 val supervisor = SupervisorJob() 8 with(CoroutineScope(coroutineContext + supervisor)) { 9 // launch the first child -- its exception is ignored for this example (don't do this in practice!) 10 val firstChild = launch(CoroutineExceptionHandler { _, _ -> }) { 11 println("The first child is failing") 12 throw AssertionError("The first child is cancelled") 13 } 14 // launch the second child 15 val secondChild = launch { 16 firstChild.join() 17 // Cancellation of the first child is not propagated to the second child 18 println("The first child is cancelled: ${firstChild.isCancelled}, but the second one is still active") 19 try { 20 delay(Long.MAX_VALUE) 21 } finally { 22 // But cancellation of the supervisor is propagated 23 println("The second child is cancelled because the supervisor was cancelled") 24 } 25 } 26 // wait until the first child fails & completes 27 firstChild.join() 28 println("Cancelling the supervisor") 29 supervisor.cancel() 30 secondChild.join() 31 } 32 } 33