wood burning stoves 2.0*
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "deserializing stacktrace" Watch "deserializing stacktrace" New topic
Author

deserializing stacktrace

Jan Radziszewski
Greenhorn

Joined: Mar 11, 2011
Posts: 3
Hi,
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.


OCPJP 6
Jan Radziszewski
Greenhorn

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
Sheriff

Joined: Oct 13, 2005
Posts: 36513
    
  16
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
Greenhorn

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:
java.io.FileNotFoundException: Cannot find /a.txt
at weblogic.net.http.HttpURLConnection.getInputStream(HttpURLConnection.java:469)
at weblogic.net.http.SOAPHttpURLConnection.getInputStream(SOAPHttpURLConnection.java:36)
at com.volantis.storefront.expressions.functions.DevicePingFunction.invoke(DevicePingFunction.java:146)

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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: deserializing stacktrace