Created
January 16, 2019 20:39
-
-
Save kspar/d2ca801fbad2941143b7d8d6317fbac0 to your computer and use it in GitHub Desktop.
Exception stack trace as string in Kotlin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.PrintWriter | |
import java.io.StringWriter | |
// Extension property on Exception | |
val Exception.stackTraceString: String | |
get() { | |
val stringWriter = StringWriter() | |
this.printStackTrace(PrintWriter(stringWriter)) | |
return stringWriter.toString() | |
} | |
// Just get stackTraceString property on any Exception, for example: | |
// val stackTrace: String = Exception().stackTraceString |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment