getStackTraceString
Converts the stack trace of this Throwable into a formatted string.
Useful for logging errors in a readable format or displaying detailed error information during development/debugging.
Usage Examples
// In error logging
try {
riskyOperation()
} catch (e: Exception) {
Log.e("MyApp", "Operation failed:\n${e.getStackTraceString()}")
}
// In crash reporting
fun reportCrash(error: Throwable) {
crashReporter.log(
message = error.message ?: "Unknown error",
stackTrace = error.getStackTraceString()
)
}
// For debugging in development builds
if (BuildConfig.DEBUG) {
println("Detailed error:\n${error.getStackTraceString()}")
}Content copied to clipboard
Receiver
Throwable The throwable whose stack trace to format.
Return
A multi-line string containing the formatted stack trace, with each frame on a new line.