What is the easiest way to convert the result of Throwable.getStackTrace()
to a string that depicts the stacktrace?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
If you are developing for Android, a far easier way is to use this:
The format is the same as getStacktrace, for e.g.
Use Throwable.printStackTrace(PrintWriter pw) to send the stack trace to an appropriate writer.
Printing stack trace to string
It's useful when you want to print the current thread stack trace without creating instance of
Throwable
- but note that creating newThrowable
and getting stack trace from there is actually faster and cheaper than callingThread.getStackTrace
.If you don't want to use an external library and you're not developing for Android, you could create an 'extension' method like this:
This should work:
The solution is to convert the stackTrace of array to string data type. See the following example: