Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[higgins-dev] Tracing your method names

All,


While refactoring DigitalSubject to Node, I've seen a lot of people tracing out their method's names for one reason or another.  Hard-coding this as a string makes it a bit of a pain to rename your methods.


One thing I've seen is people doing this:


throw new SomeException("MyClass:myMethod(String) error of some sort");


This is not needed as the caller can do: catch (SomeException e) { e.printStackTrace() }


Other places, I've seen log.trace("MyClass:myMethod(String)");


If there's not already a way to do this with log4j, please do something like this instead:

log.trace(new Exception().getStackTrace()[0].getMethodName()); or if you need the classname included:

log.trace(this.getClass().getName() + "." + new Exception().getStackTrace()[0].getMethodName());


Thanks,


Jim


Back to the top