1 // This file was automatically generated from exception-handling.md by Knit tool. Do not edit.
2 package kotlinx.coroutines.guide.exampleExceptions01
3 
4 import kotlinx.coroutines.*
5 
6 @OptIn(DelicateCoroutinesApi::class)
<lambda>null7 fun main() = runBlocking {
8     val job = GlobalScope.launch { // root coroutine with launch
9         println("Throwing exception from launch")
10         throw IndexOutOfBoundsException() // Will be printed to the console by Thread.defaultUncaughtExceptionHandler
11     }
12     job.join()
13     println("Joined failed job")
14     val deferred = GlobalScope.async { // root coroutine with async
15         println("Throwing exception from async")
16         throw ArithmeticException() // Nothing is printed, relying on user to call await
17     }
18     try {
19         deferred.await()
20         println("Unreached")
21     } catch (e: ArithmeticException) {
22         println("Caught ArithmeticException")
23     }
24 }
25