stackTraceToString

Returns the detailed description of this throwable with its stack trace.

expect fun Throwable.stackTraceToString(): String(source)
fun main() {
    try {
        // Simulate an error
        val list = listOf(1, 2, 3)
        println(list[5]) // IndexOutOfBoundsException
    } catch (e: Exception) {
        println(e.stackTraceToString())
    }
}

Source