https://kotlinlang.org logo
#coroutines
Title
# coroutines
p

Pablo

10/29/2020, 8:47 AM
Hello why my flow is not catched when an exception is thrown? my flow is
Copy code
flow {
val resultService = service.getWhatever()
val mapStuff = resultService.mapper() <-- it throws NullPointer
emit(mapStuff)
}
Then on my viewmodel I have
Copy code
usecase.execute(2)
.catch{do something}
.collect{expectedStuff}
What I'm missing? Do I have to add a 
.catch
  on my datasource so the viewmodel is aware something crashed?
g

gildor

10/29/2020, 8:51 AM
what is not catched?
r

Ruckus

10/29/2020, 3:01 PM
I believe they are asking why "why is the exception not caught (in
catch { do something }
)"
g

gildor

10/30/2020, 1:54 AM
exception will be caught by catch not sure what kind behaviour is expected, try reproduce you issue on https://play.kotlinlang.org/ this sample doesn’t look complete
p

Pablo

10/31/2020, 12:23 PM
resultService.mapper() is throwing a NPE and I thought doing the catch in the viewModel would get that crash but it closes the app
g

gildor

10/31/2020, 12:58 PM
Could.you show a some complete reproducible example, I believe there is some another problem, catch works for this case
6 Views