Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

deserializing stacktrace

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 276
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 74651
335
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
reply
    Bookmark Topic Watch Topic
  • New Topic