<lambda>null1 // This file was automatically generated from exception-handling.md by Knit tool. Do not edit.
2 package kotlinx.coroutines.guide.exampleExceptions04
3 
4 import kotlinx.coroutines.*
5 
6 @OptIn(DelicateCoroutinesApi::class)
7 fun main() = runBlocking {
8     val handler = CoroutineExceptionHandler { _, exception ->
9         println("CoroutineExceptionHandler got $exception")
10     }
11     val job = GlobalScope.launch(handler) {
12         launch { // the first child
13             try {
14                 delay(Long.MAX_VALUE)
15             } finally {
16                 withContext(NonCancellable) {
17                     println("Children are cancelled, but exception is not handled until all children terminate")
18                     delay(100)
19                     println("The first child finished its non cancellable block")
20                 }
21             }
22         }
23         launch { // the second child
24             delay(10)
25             println("Second child throws an exception")
26             throw ArithmeticException()
27         }
28     }
29     job.join()
30 }
31