Abhimanyu
06/15/2024, 12:22 PMstringResource()
throws Resources.NotFoundException
exception when the id passed is not valid.
Not to catch this? Adding try catch gives this error,
Try catch is not supported around composable function invocations.
Stylianos Gakis
06/15/2024, 5:40 PMAbhimanyu
06/15/2024, 5:43 PMstringResource()
can not be moved inside a remember
as it needs Composable scope.
I am not sure if I understood what you meant.
Can you please help share an example?Stylianos Gakis
06/15/2024, 5:47 PMStylianos Gakis
06/15/2024, 5:49 PMStylianos Gakis
06/15/2024, 5:50 PMAbhimanyu
06/17/2024, 4:16 AMval resources = LocalContext.current.resources
val string = remember {
try {
resources.getString(R.string.string_id)
} catch (exception: Resources.NotFoundException) {
null
}
}
instead of
val string = stringResource(
id = R.string.string_id,
)
I wonder why this is not the default internal implementation for stringResource()
🤔 .Stylianos Gakis
06/17/2024, 7:49 AMAbhimanyu
06/17/2024, 1:36 PM-1
.
I have changed that logic to make default as null
and I do null checks before using stringResource()
now and it works as expected.
But, I was curious to understand the recommendation on exception handling in Compose.Stylianos Gakis
06/17/2024, 2:06 PM