Skip to content

Commit 3dcc349

Browse files
authored
Make supervisor samples runnable (#2897)
Fixes #2896
1 parent dfa1b63 commit 3dcc349

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

docs/topics/exception-handling.md

+9
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ only downwards. This can easily be demonstrated using the following example:
364364
import kotlinx.coroutines.*
365365

366366
fun main() = runBlocking {
367+
//sampleStart
367368
val supervisor = SupervisorJob()
368369
with(CoroutineScope(coroutineContext + supervisor)) {
369370
// launch the first child -- its exception is ignored for this example (don't do this in practice!)
@@ -389,8 +390,10 @@ fun main() = runBlocking {
389390
supervisor.cancel()
390391
secondChild.join()
391392
}
393+
//sampleEnd
392394
}
393395
```
396+
{kotlin-runnable="true" kotlin-min-compiler-version="1.3"}
394397

395398
> You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-supervision-01.kt).
396399
>
@@ -418,6 +421,7 @@ import kotlin.coroutines.*
418421
import kotlinx.coroutines.*
419422

420423
fun main() = runBlocking {
424+
//sampleStart
421425
try {
422426
supervisorScope {
423427
val child = launch {
@@ -436,8 +440,10 @@ fun main() = runBlocking {
436440
} catch(e: AssertionError) {
437441
println("Caught an assertion error")
438442
}
443+
//sampleEnd
439444
}
440445
```
446+
{kotlin-runnable="true" kotlin-min-compiler-version="1.3"}
441447

442448
> You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-supervision-02.kt).
443449
>
@@ -468,6 +474,7 @@ import kotlin.coroutines.*
468474
import kotlinx.coroutines.*
469475

470476
fun main() = runBlocking {
477+
//sampleStart
471478
val handler = CoroutineExceptionHandler { _, exception ->
472479
println("CoroutineExceptionHandler got $exception")
473480
}
@@ -479,8 +486,10 @@ fun main() = runBlocking {
479486
println("The scope is completing")
480487
}
481488
println("The scope is completed")
489+
//sampleEnd
482490
}
483491
```
492+
{kotlin-runnable="true" kotlin-min-compiler-version="1.3"}
484493

485494
> You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-supervision-03.kt).
486495
>

0 commit comments

Comments
 (0)