1 /*
2  * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 // This file was automatically generated from exception-handling.md by Knit tool. Do not edit.
6 package kotlinx.coroutines.guide.exampleExceptions01
7 
8 import kotlinx.coroutines.*
9 
<lambda>null10 fun main() = runBlocking {
11     val job = GlobalScope.launch { // root coroutine with launch
12         println("Throwing exception from launch")
13         throw IndexOutOfBoundsException() // Will be printed to the console by Thread.defaultUncaughtExceptionHandler
14     }
15     job.join()
16     println("Joined failed job")
17     val deferred = GlobalScope.async { // root coroutine with async
18         println("Throwing exception from async")
19         throw ArithmeticException() // Nothing is printed, relying on user to call await
20     }
21     try {
22         deferred.await()
23         println("Unreached")
24     } catch (e: ArithmeticException) {
25         println("Caught ArithmeticException")
26     }
27 }
28