aboutsummaryrefslogtreecommitdiffstats
path: root/docs/topics/exception-handling.md
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-08-23 23:55:41 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-08-23 23:55:41 +0000
commitffe1b7dc19f3fbe1bc4a5f4f1e28c64cd68c5371 (patch)
tree747e5be83c6e6a2e2d9a164ebd03c5e45e6ec952 /docs/topics/exception-handling.md
parent2bbecd60d31b5d0b48847f67e741018f5ae7aa07 (diff)
parent531d55eaeac09ad6cde55687ef802d4235040985 (diff)
downloadplatform_external_kotlinx.coroutines-simpleperf-release.tar.gz
platform_external_kotlinx.coroutines-simpleperf-release.tar.bz2
platform_external_kotlinx.coroutines-simpleperf-release.zip
Snap for 7668063 from 531d55eaeac09ad6cde55687ef802d4235040985 to simpleperf-releasesimpleperf-release
Change-Id: I844c9c61f2e31a265c36a483e1509e0e08c508d6
Diffstat (limited to 'docs/topics/exception-handling.md')
-rw-r--r--docs/topics/exception-handling.md15
1 files changed, 13 insertions, 2 deletions
diff --git a/docs/topics/exception-handling.md b/docs/topics/exception-handling.md
index fbd11313..3facd51a 100644
--- a/docs/topics/exception-handling.md
+++ b/docs/topics/exception-handling.md
@@ -19,9 +19,16 @@ exception, for example via [await][Deferred.await] or [receive][ReceiveChannel.r
It can be demonstrated by a simple example that creates root coroutines using the [GlobalScope]:
+> [GlobalScope] is a delicate API that can backfire in non-trivial ways. Creating a root coroutine for the
+> whole application is one of the rare legitimate uses for `GlobalScope`, so you must explicitly opt-in into
+> using `GlobalScope` with `@OptIn(DelicateCoroutinesApi::class)`.
+>
+{type="note"}
+
```kotlin
import kotlinx.coroutines.*
+@OptIn(DelicateCoroutinesApi::class)
fun main() = runBlocking {
val job = GlobalScope.launch { // root coroutine with launch
println("Throwing exception from launch")
@@ -90,6 +97,7 @@ so its `CoroutineExceptionHandler` has no effect either.
```kotlin
import kotlinx.coroutines.*
+@OptIn(DelicateCoroutinesApi::class)
fun main() = runBlocking {
//sampleStart
val handler = CoroutineExceptionHandler { _, exception ->
@@ -184,6 +192,7 @@ which is demonstrated by the following example.
```kotlin
import kotlinx.coroutines.*
+@OptIn(DelicateCoroutinesApi::class)
fun main() = runBlocking {
//sampleStart
val handler = CoroutineExceptionHandler { _, exception ->
@@ -242,6 +251,7 @@ import kotlinx.coroutines.exceptions.*
import kotlinx.coroutines.*
import java.io.*
+@OptIn(DelicateCoroutinesApi::class)
fun main() = runBlocking {
val handler = CoroutineExceptionHandler { _, exception ->
println("CoroutineExceptionHandler got $exception with suppressed ${exception.suppressed.contentToString()}")
@@ -292,6 +302,7 @@ Cancellation exceptions are transparent and are unwrapped by default:
import kotlinx.coroutines.*
import java.io.*
+@OptIn(DelicateCoroutinesApi::class)
fun main() = runBlocking {
//sampleStart
val handler = CoroutineExceptionHandler { _, exception ->
@@ -497,7 +508,7 @@ The scope is completed
[CoroutineExceptionHandler]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-exception-handler/index.html
[Job]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/index.html
[Deferred]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/index.html
-[Job.cancel]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/cancel.html
+[Job.cancel]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/cancel.html
[runBlocking]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/run-blocking.html
[SupervisorJob()]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-supervisor-job.html
[Job()]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job.html
@@ -510,4 +521,4 @@ The scope is completed
[produce]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/produce.html
[ReceiveChannel.receive]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/receive.html
-<!--- END --> \ No newline at end of file
+<!--- END -->