I've encoutered such issue, that android studio warns me about unreachable code. I don't understand, how it is unreachable.
My original code:
try {
return BasketProvider.valueOf(prefs.getString(KEY_BASKET_PROVIDER, null)) //unreachable code here
} finally {
return BasketProvider.LOCAL
}
If I change finally to catch(e :IllegalArgumentException)
, there's no warning. If I combine all of them, the warning appears again.
try {
return BasketProvider.valueOf(prefs.getString(KEY_BASKET_PROVIDER, null))//no warning
} catch (e: IllegalArgumentException) {
return BasketProvider.LOCAL
}
--------------------------------
try {
return BasketProvider.valueOf(prefs.getString(KEY_BASKET_PROVIDER, null))//unreachable code
} catch (e: IllegalArgumentException) {
return BasketProvider.LOCAL //unreachable code
} finally {
return BasketProvider.LOCAL
}
Is this a Kotlin bug, or am I missing something?
EDIT:
Basket provider is simple enum class:
enum class BasketProvider {
LOCAL, SHARED
}