• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

deserializing stacktrace

 
Jan Radziszewski
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 276
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50168
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic