I have started working with a large code base, and a lot of the code has been set up with a strange format for functions. more or less every function has the following format
foo(){
trace_messages()
// this is what I don't get
try{
// all code goes here
} finally {
trace_messages()
}
}
I can’t see any sense behind the insistence on wrapping more or less the entire work of function in a try. Is this some sort of ‘best practice’ that I never got told about?
EDIT:
perhaps I should have stated, but the two calls to trace_messages() are actually different sections of code, but more or less the same… if you follow my meaning
The intention of that code was to make sure that
trace_messages()was guaranteed to executed in the beginning and before the end offoo().finallyis guaranteed to execute both in case everything runs fine, and if the code insidetryfails miserably with some nasty uncaught runtime exception.I agree that the format chosen to achieve this intention is not of the best, normally that is done with some sort of AOP, in Spring you would wrap
foo()into Around advice.