Skip to main content

Posts

Showing posts from November, 2007

Using Throwable to trace the origin of an object

When using components decoupled by queues or other intermediate data stores, it can be a pain to trace the origin of faulty data in the queue. In languages with decent support for stack traces, however, it's easy. In Java, you just add a temporary field public final Throwable createdBy = new Throwable(); to the class in question. Or, if you need to know who enqueued it where, you vary the creation of the Throwable accordingly. (See example 8-5 of logging in the Red Hat Web Application Framework, too.)