So I have written a large chunk of code that mostly has the following lines
public <method_constraint> <methodname>(<some args>) {
try {
// do some logic here
} catch(Exception e) {
// do some logic here
} finally {
//do some logic here
}
}
Some of those catch lines have e.printStackTrace();
while some of them don't.
I'm looking at SpringAOP to create some JoinPoints and PointCuts to handle that. Is there anyway for me to actually log the exception being caught without the function throwing out an exception?
What I'm trying to achieve here is whenever I have a 'catch' line, I would like to log the stacktrace of the exception on that catch line.
Is this possible?
Here is one of my existing Aspects. This logs all the method calls made:
@Aspect
@Component
public class MethodCallAspect {
private static DebugManager logger = DebugManager.getInstance(MethodCallAspect.class);
@Before("execution(* com.cistera..*(*))")
public void loggingAdvice(JoinPoint joinPoint) {
StringBuilder methodCall = new StringBuilder(joinPoint.getTarget().getClass().toString()).append(" - ").append(joinPoint.getSignature().getName());
logger.debug(methodCall.toString());
}
}
PS: I could go into each class and log the stacktrace from each 'catch' line but that will be a pain having to update a lot of code.
Thank you.