1 /* <lambda>null2 * 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.exampleExceptions02 7 8 import kotlinx.coroutines.* 9 10 @OptIn(DelicateCoroutinesApi::class) 11 fun main() = runBlocking { 12 val handler = CoroutineExceptionHandler { _, exception -> 13 println("CoroutineExceptionHandler got $exception") 14 } 15 val job = GlobalScope.launch(handler) { // root coroutine, running in GlobalScope 16 throw AssertionError() 17 } 18 val deferred = GlobalScope.async(handler) { // also root, but async instead of launch 19 throw ArithmeticException() // Nothing will be printed, relying on user to call deferred.await() 20 } 21 joinAll(job, deferred) 22 } 23