RE: [coldbox:16249] [coldbox-3.5.2] Getting Stack Trace Array from ExceptionBean

You’re correct that the ColdBox Exception object is duplicating the actual error object on init which is converting it from a Java Exception object to a simple struct.

The equivilant data is accessible with ExceptionBean.getStackTrace() but that is going to return to string, not an array of java.lang.StackTraceElement objects. If all your legacy code is doing is looping over the array and calling toString on the StackTraceElements, it would be easiest to just get the string from the ExceptionBean anyway, but I understand that you’d have to touch your legacy code to accept the string instead.

I’ll be honest, I’m not sure why we duplicate the error struct. It may have to do with asynchronous logging but that’s just a guess. I’d say you have 3 options (ranked in the order of what I would recommend):

  1. Modify the legacy code to use the StackTrace string (and hope there’s not a good reason why it was using getStackTrace())

  2. Modify the ExceptionBean not to duplicate (and hope there’s not a good reason why it is doing that)

  3. Decorate the ExceptionBean and take the StackTrace string and build your own array of java.lang.StackTraceElement objects out of it to fake a getStackTrace() method back in. (This is possible, but a messy last resort in my opinion)

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Hi Brad–

Thanks for the suggestions. On #2, what are your thoughts on adding the actual error object to the ExceptionBean? That way, the duplicate can still occur but the exception object will still be available as well.

#3, though messy, is intriguing to me as well. I might have to explore that a bit, just for fun :slight_smile:

Thanks again!