<lambda>null1// This file was automatically generated from exception-handling.md by Knit tool. Do not edit. 2 package kotlinx.coroutines.guide.exampleExceptions06 3 4 import kotlinx.coroutines.* 5 import java.io.* 6 7 @OptIn(DelicateCoroutinesApi::class) 8 fun main() = runBlocking { 9 val handler = CoroutineExceptionHandler { _, exception -> 10 println("CoroutineExceptionHandler got $exception") 11 } 12 val job = GlobalScope.launch(handler) { 13 val innerJob = launch { // all this stack of coroutines will get cancelled 14 launch { 15 launch { 16 throw IOException() // the original exception 17 } 18 } 19 } 20 try { 21 innerJob.join() 22 } catch (e: CancellationException) { 23 println("Rethrowing CancellationException with original cause") 24 throw e // cancellation exception is rethrown, yet the original IOException gets to the handler 25 } 26 } 27 job.join() 28 } 29