Since JDK 1.4, the Throwable class has the "getStackTrace()" method, which returns an array of StackTraceElement objects, which can tell you the name of the method.
String methodName = new Throwable().getStackTrace[0].getMethodName();
In real code, I wouldn't chain all this together: getStackTrace() can return a 0-length array. You'd have to check for that.
The above posts do give good guidance about how to get the current method name. However, I am a bit doubtful why you want to do that, in your particular example.
Do the exception messages really need to contain the method name? The exception stack traces will make the method name clear anyway. Perhaps you are logging exception messages, but not logging stack traces?
If you do need the method name in the message, I would have thought it would be quicker for you, faster to execute, easier to maintain just to "bite the bullet" and type in those 40 method names. If you want to be really flash, a smart editor could probably be programmed to do it automatically (I reckon I could get emacs to do it).
In general, always favour simple obvious code over clever code. As a rule, if someone says your code is "clever", it's an insult, not a compliment!
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
There are 10 kinds of people in this world. Those that understand binary get this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss