Breaking News
Home / Java / Java Snippets / Get StackTrace as String

Get StackTrace as String

Java StackTrace

Its easy to print the stack trace using e.printStackTrace() where e is instance of an Exception/Throwable. This prints the trace to the Standard Error stream. But how about if you want to have the stacktrace stored in file or database or want to search as text.

This snippets shows how to get the stack trace as String.


The output is as follows:

java.lang.RuntimeException: Exception : some thing wrong here!
at com.livrona.snippets.system.PrintStackTrace.methodC(
at com.livrona.snippets.system.PrintStackTrace.methodB(
at com.livrona.snippets.system.PrintStackTrace.methodA(
at com.livrona.snippets.system.PrintStackTrace.exec(
at com.livrona.snippets.system.PrintStackTrace.main(


Check Also

How to progamatically get the Java version?

Snippet The key here is to use the system property java.version and get minor and …

Advertisment ad adsense adlogger