tags:

views:

63

answers:

2

I am using Groovy in a Java Swing application as part of my plan to force-feed myself dynamic languages until I like them (which is happening, partly).

My stack traces are filled with Groovy stuff like

org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor

is there a way to get Eclipse to remove all of that codehaus stuff (filter stack traces, basically)?

Edit: I can do this from the command-line with grep (well, not yet) so it's not so bad, but inside of Eclipse would be great too.

+5  A: 

There is a Utility in Groovy that does exactly what you want: StackTraceUtils. STU will clean all the callsite information from your stacktrace, leaving the stuff you're really interested in.

Edit: In Java you will have to encasulate the exception in a java.lang.RuntimeExceptionaccording to comments.

Example of usage:

try {
    1/0;
} catch (Throwable t) {
    throw new RuntimeException(org.codehaus.groovy.runtime.StackTraceUtils.sanitize(t)); //Modifies the Throwable and rethrows
}

StackTraceUtils is available in the latest version of Groovy and originally comes from Grails. I'm not sure how you would go about applying this to all of your projects stacktraces but I think both Griffon and Grails does it so there should be some hints in those projects.

xlson
Good stuff, THANK YOU!
Yar
I'll mark this as best answer for now, but if someone comes along who can tell me how to get Eclipse to do this... But for me this did work.
Yar
You're welcome. You should be able to make this happen automatically for all uncaught stacktraces using java.lang.Thread.UncaughtExceptionHandler which allows you register an exceptionhandler for uncaught exceptions but I haven't been able to get this to work. Read more about this here: http://dabblescribble.blogspot.com/2009/11/starting-out-in-griffon-3-logging.html
xlson
Thanks @xlson, I've gotten this to work. Ironically, to get it to compile in Java, you have to wrap the sanitize return in a RuntimeException.... the joys of checked exceptions :)
Yar
Your welcome @yar :) Ofcourse, I soo don't miss them from my Java days. Added your tip to the answer!
xlson
+1  A: 

I don't have an answer for "Run as Groovy application", but if you run GroovyTestcases as jUnit tests in Eclipse, there is a "filter stack traces" button above the stack trace view.

slim
+1 we are getting closer!
Yar