• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.exampleExceptions05
7 
8 import kotlinx.coroutines.exceptions.*
9 
10 import kotlinx.coroutines.*
11 import java.io.*
12 
13 @OptIn(DelicateCoroutinesApi::class)
14 fun main() = runBlocking {
15     val handler = CoroutineExceptionHandler { _, exception ->
16         println("CoroutineExceptionHandler got $exception with suppressed ${exception.suppressed.contentToString()}")
17     }
18     val job = GlobalScope.launch(handler) {
19         launch {
20             try {
21                 delay(Long.MAX_VALUE) // it gets cancelled when another sibling fails with IOException
22             } finally {
23                 throw ArithmeticException() // the second exception
24             }
25         }
26         launch {
27             delay(100)
28             throw IOException() // the first exception
29         }
30         delay(Long.MAX_VALUE)
31     }
32     job.join()
33 }
34