• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
10 @OptIn(DelicateCoroutinesApi::class)
<lambda>null11 fun main() = runBlocking {
12     val job = GlobalScope.launch { // root coroutine with launch
13         println("Throwing exception from launch")
14         throw IndexOutOfBoundsException() // Will be printed to the console by Thread.defaultUncaughtExceptionHandler
15     }
16     job.join()
17     println("Joined failed job")
18     val deferred = GlobalScope.async { // root coroutine with async
19         println("Throwing exception from async")
20         throw ArithmeticException() // Nothing is printed, relying on user to call await
21     }
22     try {
23         deferred.await()
24         println("Unreached")
25     } catch (e: ArithmeticException) {
26         println("Caught ArithmeticException")
27     }
28 }
29