aspose file tools
The moose likes Java in General and the fly likes deserializing stacktrace Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "deserializing stacktrace" Watch "deserializing stacktrace" New topic

deserializing stacktrace

Jan Radziszewski

Joined: Mar 11, 2011
Posts: 3
Is there any class that automatically parse the stack trace as a String and create an Exception with filled all elements?
Vinoth Kumar Kannan
Ranch Hand

Joined: Aug 19, 2009
Posts: 276

When you invoke getStackTrace() on a Throwable object, it gives back you an array of java.lang.StackTraceElement - each element representing a single line in the stack trace.
You need not parse the stack trace at all, as it is just an aggregation of individual data.
Try exploring the java.lang.StackTraceElement class for more info.

Jan Radziszewski

Joined: Mar 11, 2011
Posts: 3
Please note, that I don't have Exception object. I have only a String and I want to convert/map to proper object of Exception. So your solution doesn't solve my problem.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 41584
Welcome to the Ranch

You can probably split the stack trace on line ends. There is an Exception constructor which takes a String argument. I don't know whether those two suggestions are any help to you.
Jan Radziszewski

Joined: Mar 11, 2011
Posts: 3
No, I don't want Exception but specific one that is defined in the stack trace. Let say I have the following stack trace: Cannot find /a.txt
at com.volantis.storefront.expressions.functions.DevicePingFunction.invoke(

So having above stack trace as a String I would like to create FileNotFoundException object with message and all stack trace elements.
Is there any tool that can do it automatically for me. I don't want to parse it manually.
Anyone know something like that?
jQuery in Action, 2nd edition
subject: deserializing stacktrace