Sunday, January 22, 2006


Exit from Java

Recently I had to solve the problem for one to be able to uniquely identify the place where an exception was thrown by our Java application, and this without having access to the stack trace. Of course one can do funny things like:

throw new RuntimeException("Call the help desk (unique error code: 12e4ad7f)");

but this feels to much like Cobol, right. I wanted to somehow automate this. Since I didn't find any tool on the net that could possibly help me with this job I wrote one myself. The idea behind this tool is to instrument each:


byte code with the following sequence:

instanceof the.base.exception.class
ifeq nope
checkcast the.base.exception.class
ldc "my-uuid"
invokevirtual the.base.exception.class.setIdentifier(L/java/lang/String;)V
That way, when the application throws an exception, the place where this happens is automatically assigned a unique identifier.

The implementation of the tool uses BCEL for the actual byte code instrumentation of your classes. I was surprised by the architecture of BCEL; nice toolbox this is. Of course I also wrote an Ant task to make the tool easy to use. Since I could use some help/feedback on writing a smarter version of the Ant task, I open sourced the tool under the GPL. The project is called ExId, as in 'Exception Identification', or just as in 'exit'. It's available from:

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?