How to print the complete stack trace of the exception using a velocity template
My present template has $exception as template variable, which contains the exception.
How to print the complete stack trace of the exception using a velocity template
My present template has $exception as template variable, which contains the exception.
In case you want to display the trace on the output you could wrap the evaluate method inside try-catch-finally block. In catch write the stack trace or just the message of the exception to the writer. In the finally section just flush the writer.
Something like this if I remember right:
StringWriter w = new StringWriter();
try {
Velocity.evaluate( context, w, "mystring", s );
} catch (Exceptions... e)
w.write(e.getMessage());
} finally {
w.flush();
}
In velocity this is how i solved this problem.
#foreach ($i in [1..3]) #if($exception.Cause) #set($exception = $exception.Cause) #foreach($stack in $exception.getStackTrace()) $stack.toString() #end #end #end