-1

Lets say I have a function like this

public JSONObject parseMessage(InputStream fileName) throws Exception { 

And it throws an error where can I get the stack trace of that?

I know if I have something like

try {} catch(Exception e) {//I could save it to a var here}

But how to I save the stacktrace to are variable with a function that throws Exception?

Thanks for all the help

2
  • You want to get the stacktrace in a function before you throw an exception from that function? Commented Oct 28, 2016 at 22:12
  • You could catch it, work on it, and then throw it again. Commented Oct 28, 2016 at 22:13

1 Answer 1

0

You can use Apache commons to convert an Exception stack trace to String.

This class is available in Apache commons-lang-2.2.jar:

org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(Throwable)
Sign up to request clarification or add additional context in comments.

2 Comments

Or just use the existing .getStackTrace() which returns StackTraceElement[] which has a perfectly good .toString().
Or Arrays.toString(Thread.currentThread().getStackTrace());.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.