I am working on a Swing application which uses SwingWorker to perform logic in the background. I tried to write an aspect to remove the error handling from class A(and several others) and centralize it using aspectJ. So far I wasn't able to write a pointcut to catch doInBackground
and propertyChange
methods.
@Component
public class A{
public void perform(final String val) {
final SwingWorker<String, Object> myWorker = new SwingWorker<String, Object>(){
@Override
protected String doInBackground() throws Exception {
String response = null;
try{
//do logic and return response
}catch(MyException e){
response "myexception";
}catch(MyException2 e){
response "myexception2";
}catch(Exception e){
response = "fatal exception"
}
return response;
}
};
myWorker.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
try {
//do logic
}catch(MyException3 e){
//do logic
}catch(Exception e){
//do logic
}
}
});
myWorker.execute();
}
}