Catch exceptions from children

Report a typo

This time, we're loading data of two types. One of those may not be important, so we want to know if something went wrong but don't want to the whole application to fail when the loading fails.

Your job is to define the proper coroutines context, which will:

  • prevent exceptions in any children job from propagating up and crashing the app;
  • print any exception's message to console in a separate line (use the `.message` property of an exception).

Tip: You'll need more than one element in the context to stop exception propagation and to print the exceptions.

Write a program in Kotlin
// Define a proper scope here
// and make sure it doesn't propagate exception
// but prints exception's `.message` to console
// val mainScope =

suspend fun main() {
// we load data in the main scope
// and wait for it to finish explicitly
// so there is no need to call 'runBlocking'
// also no need to modify this code
val job1 = mainScope.loadDataButFail()
val job2 = mainScope.loadData()
joinAll(job1, job2)
}
___

Create a free account to access the full topic