I have a proposal: Allow reified exception type pa...
# language-proposals
l
I have a proposal: Allow reified exception type parameters in try catch blocks found inside inline functions.
Copy code
private inline fun <reified E : Exception> throwOrReport(f: () -> Unit) {
    try {
        f()
    } catch (e: E) { //Currently, compiler says: "Reified type is forbidden for catch parameter"
        if (BuildConfig.DEBUG) throw e else <http://Timber.wtf|Timber.wtf>(e)
    }
}
s
Some comments from Andrey Breslav here https://youtrack.jetbrains.com/issue/KT-9742
👍🏽 1
r
Scala has a
NonFatal
control mechanism that would be handy for these cases in Kotlin too, though in Scala is based on unapply and pattern matching but something similar in Kotlin would be awesome and complimentary to reified type args in exc blocks. http://www.scala-lang.org/api/2.12.1/scala/util/control/NonFatal$.html