Please feel free to edit the question or ask more detailed information about the quest.
I know that I can log ArithmeticException method below using aspectJ as.
public void afterThrowingAspect(){ System.out.println("This is afterThrowingAspect() !"); int i=2/0; System.out.println("i value : "+i); }
The AspectJ class has
@AfterThrowing(pointcut = "execution(* com.pointel.aop.test1.AopTest.afterThrowingAspect(..))",throwing= "error") public void logAfterError(JoinPoint joinPoint,Throwable error) { System.out.println("Hi jacked Method name : " + joinPoint.getSignature().getName()); log.info("Method name : " + joinPoint.getSignature().getName()); log.info("Error report is : " + error); }
Usually I can handle the exception using TRY and CATCH blocks and log errors in each CATCH block, like,
public void someMehtod(){ try{ int i=2/0; System.out.println("i value : "+i); }catch{ArithmeticException err){ log.info("The exception you got is : " + err); } }
But I donβt like doing logging as with every single CATCH block separately in all java classes of my project, for example,
log.info("The exception you got is : " + err);
I would like to make a logging block inside CATCH in my application using the aspectJ class.
Hope you all understand my question. Thanks.
source share