javastack-tracethrowable

Convert a string to stack trace in java


I have multiple stack traces and I want to generate unique id for each of them using the Throwable methods like getStackTrace, getCause etc. The problem I am facing is that these stack traces are already generated and I am fetching them from a db where they have been stored as strings. Is there any way I could convert them back to Throwable?


Solution

  • Exception implements Serializable. If you store your exceptions into the database using Java's serialization API, you should be able to deserialize them back into Exception objects using that same API.

    See https://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html for the official documentation on this.

    If you do not currently store them through that mechanism, you are out of luck and will need to change that.