We cannot able to use `try-catch` inside composable function. I am getting the below error `Try catc...
a
We cannot able to use
try-catch
inside composable function. I am getting the below error
Try catch is not supported around composable function invocations.
πŸ˜„ 2
k
why do you want to throw?
a
Just getting some error and I am trying to printstacktrace.πŸ˜…
m
He doesn't want to throw, but catch ;)
🀣 1
a
Yes
I believed that we can able to use every functionality provided by kotlin.
l
@Michal Bacik he can catch inside the function, without calling nested
@Composable
inside the try-catch
a
Thanks to the way Compose can restart further down the tree on recomposition if just one small part of the UI invalidates, the try/catch may not be part of the call stack when the error happens. Any time you call a composable function, think of it being a little bit like a
launch {}
.
We might wire this up to try to make it do something reasonable but it's not top priority at the moment
l
I really don’t see the point why you should wrap a
@Composable
with a try-catch block
βž• 1
a
No? I'd love to be able to try a block and if anything goes wrong, transactionally roll back some part of it and then emit something else as part of the catch πŸ™‚
l
Well, you can try-catch inside a composable
a
Yes but that's not really exceptions, that's more like return value checking at each layer of the call stack
It unfortunately is a hole in our goal that any chunk of compose code is a candidate for refactor/extract method
One that can be worked around, but still
2429 Views