How can I handle the case where a CompositionLocal object is not available to a composable? I can't use try catch as "Try catch is not supported around composable function invocations."
Consider the following code:
// LocalElevations.kt file
data class Elevations(val card: Dp = 0.dp, val default: Dp = 0.dp)
// Define a CompositionLocal global object with a default
// This instance can be accessed by all composables in the app
val LocalElevations = compositionLocalOf { Elevations() }
// Somewhere else, try to access the current value of LocalElevations
val elevations: Elevations
// ISSUE HERE: Compiler complains: "Try catch is not supported around composable function invocations."
try {
elevations = LocalElevations.current
} catch (e: IllegalStateException) {
// use default values etc.
}