This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hm, it seems of limited use. If I'm logging the end of a method, I would probably like to know whether the method completed normally or threw an exception. Putting the log statement in a finally treats these two cases exactly the same. In general I would rather use-aspect oriented programming here to insert log statements to automatically log any return statement, as a return, and log any error as an error, without cluttering up the code. While we're at it, it's often nice to log the return value, if there is one.
Can you please elaborate more how you will use "aspect oriented programming to insert "method start" and "method end" logs".
Do you find it valid to use finally to just log one logger?
Do finally cause an extra overhead as compared to code with no finally block?
Joined: Jan 30, 2000
[Abdul]: Can you please elaborate more how you will use "aspect oriented programming to insert "method start" and "method end" logs".
There's a good article on the subject here. There are probably other ways to do it using other aspect-oriented frameworks, like Spring AOP and JBoss AOP.
[Abdul]: Do you find it valid to use finally to just log one logger?
I suppose, but I don't think it's very useful, for the reasons I mentioned.
[Abdul]: Do finally cause an extra overhead as compared to code with no finally block?
In general, no, the finally block really doesn't create any special overhead. Of course whatever you do in the finally block might, if it's a slow operation. But if it's something that needs to be done, it needs to be done.