with changing `launch` to `async` and `join` to `a...
# coroutines
e
with changing
launch
to
async
and
join
to
await
everything start to work as expect, I see all three catch (as described in https://github.com/Kotlin/kotlinx.coroutines/issues/61). But with
launch
its very strange that
method-catch
doesn’t call
e
I know that with async/await it’s possible to do it (i have mentioned it in question). The question was about
launch
, about why it’s don’t catched from not suspend method
c
when you launch something you have to think about it as it off on another world. So if an exception happens over on Mars you would never know about it on Earth. The await function provides a bridge to join the two worlds so they can interact. That analogy fell apart rather quickly…
v
launch
is equivalent of running a thread in coroutines world. When you write
Copy code
val thread = thread { throw Exception() }
thread.join()
You don’t expect for
join
to throw, do you? Same about
launch
. But
async
returns
Deferred
, which is analogue of the
Future
in coroutines world. And
future.get
throws an exception if related computation failed with exception
Basically
launch
is fire-and-forget job, while
async
is asynchronous computation which should return its result at some point
e
@codyoss, @Vsevolod Tolstopyatov [JB] thanks for explanation, and especially for the analogy with the thread. Now it’s much clearer.
u
Does a `launch`ed child with an unhandled exception in today's implementation cancel it's parent with that exception, as it used to be the behaviour?
v
@uli it cancels child with that exception. Though this mechanism is slightly non-deterministic and being reworked under https://github.com/Kotlin/kotlinx.coroutines/issues/333 to provide consistent behaviour for users. As soon as it’s ready I will add guide section about exceptions mental model
👍 1
u
Thanks @Vsevolod Tolstopyatov [JB] for the update