Last active
May 20, 2018 15:12
-
-
Save KenjiOhtsuka/3d728ebd4c0df8bed29756826753982c to your computer and use it in GitHub Desktop.
How to Print Stack Trace at Any Point in Kotlin
This file contains 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
/* | |
* Throwable, StackTraceElement is in java.lang | |
* | |
* StackTraceElement has the following attributes (get methods) | |
* className | |
* methodName | |
* fileName | |
* lineNumber | |
*/ | |
fun printStackTrace() { | |
Throwable().stackTrace.forEach { | |
println(it.className + "#" + it.methodName + "(" + it.fileName + ":" + it.lineNumber + ")") | |
} | |
} | |
fun main(args: Array<String>) { | |
printStackTrace() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment