I have a problem.
Namely: I’m using spring aop to handle exceptions. Some of them are my exceptions that are being thrown in case of corrupted data delivered by outside vendor. I handle them in aspects pointed to certain type. Such as this one.
@AfterThrowing(
pointcut =
"execution(*myClass.myDataProcessingMethod(..))",
throwing = "ex"
)
public void myAspectMethod(MyException ex) {
...
}
But when something bad happends in my data processing job, and it isn’t faulty data but bug in my logic, I want to be informed on instance. So i have a second aspect.
@AfterThrowing(
pointcut =
"execution(*myClass.myDataProcessingMethod(..))",
throwing = "ex"
)
public void myAspectMethod(Exception ex) {
extraInformingService.informAdamAtOnce("shitjustgotreal");
}
But when MyException is thrown both aspects are fired because MyException is instance of Exception to.
Is there a way to fire only the method that points to MyException ?
The easiest, albeit not very elegant version is this: