Using @AfterThrowing with @ExceptionHandler











up vote
3
down vote

favorite
1












import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;

@Aspect
public class ExceptionAlerts {
public ExceptionAlerts() {
System.err.println("Class Scanned");
}

@AfterThrowing(pointcut = "com.name.papp.star", throwing = "ex")
public void doRecoveryAction(Throwable ex) throws Throwable {
System.err.println(">>>>>>>>>>>>>>>>Recovery Actions++++++++++++++++");
}
}


Service Interface



public interface SignInService {
CustomerSignInDTO signIn()
throws LappException;
}


Service Implementation Class



public class SignInServiceImpl implements SignInService {
@Override
@Transactional(readOnly = false, rollbackFor = Exception.class)
public CustomerSignInDTO signInCustomer(CustomerDeviceDTO customerDeviceDTO,
String mobileNumber, boolean createIfNotExist)
throws LappException {
// Throwing Exception Here
}
}


Problem -
Spring-Boot-1.2.5



The method doRecoveryActions never gets called. I am also using @ExceptionHandler somewhere to prepare the error response. Is it because @ExceptionHandler catches all the exceptions and doRecoveryActions is never called? Any suggestions would be appreciated!










share|improve this question
























  • Does it work if you change signature to doRecoveryAction(Throwable ex)?
    – Ermintar
    Nov 19 at 9:40










  • No it doesn't. Tried that as well.
    – kashish verma
    Nov 19 at 9:43










  • Pls, post the real pointcut & executed method signature. @ExceptionHandler doesn't spoil AOP handlers
    – Ermintar
    Nov 19 at 9:46










  • Trouble is with your pointcut expression. Try pointcut = "execution(* com.name.papp.star.*)" to scan full package or "execution(* com.name.papp.star.auth.service.impl.signInCustomer(..))" for exact method
    – Ermintar
    Nov 19 at 10:20










  • Around("execution(* com..*ServiceImpl.*(..))") works perfectly with Around , but gives error when I use AfterThrowing. Could you please suggest an alternate, I have to give package based restrictions.
    – kashish verma
    Nov 19 at 12:52















up vote
3
down vote

favorite
1












import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;

@Aspect
public class ExceptionAlerts {
public ExceptionAlerts() {
System.err.println("Class Scanned");
}

@AfterThrowing(pointcut = "com.name.papp.star", throwing = "ex")
public void doRecoveryAction(Throwable ex) throws Throwable {
System.err.println(">>>>>>>>>>>>>>>>Recovery Actions++++++++++++++++");
}
}


Service Interface



public interface SignInService {
CustomerSignInDTO signIn()
throws LappException;
}


Service Implementation Class



public class SignInServiceImpl implements SignInService {
@Override
@Transactional(readOnly = false, rollbackFor = Exception.class)
public CustomerSignInDTO signInCustomer(CustomerDeviceDTO customerDeviceDTO,
String mobileNumber, boolean createIfNotExist)
throws LappException {
// Throwing Exception Here
}
}


Problem -
Spring-Boot-1.2.5



The method doRecoveryActions never gets called. I am also using @ExceptionHandler somewhere to prepare the error response. Is it because @ExceptionHandler catches all the exceptions and doRecoveryActions is never called? Any suggestions would be appreciated!










share|improve this question
























  • Does it work if you change signature to doRecoveryAction(Throwable ex)?
    – Ermintar
    Nov 19 at 9:40










  • No it doesn't. Tried that as well.
    – kashish verma
    Nov 19 at 9:43










  • Pls, post the real pointcut & executed method signature. @ExceptionHandler doesn't spoil AOP handlers
    – Ermintar
    Nov 19 at 9:46










  • Trouble is with your pointcut expression. Try pointcut = "execution(* com.name.papp.star.*)" to scan full package or "execution(* com.name.papp.star.auth.service.impl.signInCustomer(..))" for exact method
    – Ermintar
    Nov 19 at 10:20










  • Around("execution(* com..*ServiceImpl.*(..))") works perfectly with Around , but gives error when I use AfterThrowing. Could you please suggest an alternate, I have to give package based restrictions.
    – kashish verma
    Nov 19 at 12:52













up vote
3
down vote

favorite
1









up vote
3
down vote

favorite
1






1





import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;

@Aspect
public class ExceptionAlerts {
public ExceptionAlerts() {
System.err.println("Class Scanned");
}

@AfterThrowing(pointcut = "com.name.papp.star", throwing = "ex")
public void doRecoveryAction(Throwable ex) throws Throwable {
System.err.println(">>>>>>>>>>>>>>>>Recovery Actions++++++++++++++++");
}
}


Service Interface



public interface SignInService {
CustomerSignInDTO signIn()
throws LappException;
}


Service Implementation Class



public class SignInServiceImpl implements SignInService {
@Override
@Transactional(readOnly = false, rollbackFor = Exception.class)
public CustomerSignInDTO signInCustomer(CustomerDeviceDTO customerDeviceDTO,
String mobileNumber, boolean createIfNotExist)
throws LappException {
// Throwing Exception Here
}
}


Problem -
Spring-Boot-1.2.5



The method doRecoveryActions never gets called. I am also using @ExceptionHandler somewhere to prepare the error response. Is it because @ExceptionHandler catches all the exceptions and doRecoveryActions is never called? Any suggestions would be appreciated!










share|improve this question















import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;

@Aspect
public class ExceptionAlerts {
public ExceptionAlerts() {
System.err.println("Class Scanned");
}

@AfterThrowing(pointcut = "com.name.papp.star", throwing = "ex")
public void doRecoveryAction(Throwable ex) throws Throwable {
System.err.println(">>>>>>>>>>>>>>>>Recovery Actions++++++++++++++++");
}
}


Service Interface



public interface SignInService {
CustomerSignInDTO signIn()
throws LappException;
}


Service Implementation Class



public class SignInServiceImpl implements SignInService {
@Override
@Transactional(readOnly = false, rollbackFor = Exception.class)
public CustomerSignInDTO signInCustomer(CustomerDeviceDTO customerDeviceDTO,
String mobileNumber, boolean createIfNotExist)
throws LappException {
// Throwing Exception Here
}
}


Problem -
Spring-Boot-1.2.5



The method doRecoveryActions never gets called. I am also using @ExceptionHandler somewhere to prepare the error response. Is it because @ExceptionHandler catches all the exceptions and doRecoveryActions is never called? Any suggestions would be appreciated!







java spring-aop






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









pushkin

3,738102450




3,738102450










asked Nov 19 at 9:34









kashish verma

664




664












  • Does it work if you change signature to doRecoveryAction(Throwable ex)?
    – Ermintar
    Nov 19 at 9:40










  • No it doesn't. Tried that as well.
    – kashish verma
    Nov 19 at 9:43










  • Pls, post the real pointcut & executed method signature. @ExceptionHandler doesn't spoil AOP handlers
    – Ermintar
    Nov 19 at 9:46










  • Trouble is with your pointcut expression. Try pointcut = "execution(* com.name.papp.star.*)" to scan full package or "execution(* com.name.papp.star.auth.service.impl.signInCustomer(..))" for exact method
    – Ermintar
    Nov 19 at 10:20










  • Around("execution(* com..*ServiceImpl.*(..))") works perfectly with Around , but gives error when I use AfterThrowing. Could you please suggest an alternate, I have to give package based restrictions.
    – kashish verma
    Nov 19 at 12:52


















  • Does it work if you change signature to doRecoveryAction(Throwable ex)?
    – Ermintar
    Nov 19 at 9:40










  • No it doesn't. Tried that as well.
    – kashish verma
    Nov 19 at 9:43










  • Pls, post the real pointcut & executed method signature. @ExceptionHandler doesn't spoil AOP handlers
    – Ermintar
    Nov 19 at 9:46










  • Trouble is with your pointcut expression. Try pointcut = "execution(* com.name.papp.star.*)" to scan full package or "execution(* com.name.papp.star.auth.service.impl.signInCustomer(..))" for exact method
    – Ermintar
    Nov 19 at 10:20










  • Around("execution(* com..*ServiceImpl.*(..))") works perfectly with Around , but gives error when I use AfterThrowing. Could you please suggest an alternate, I have to give package based restrictions.
    – kashish verma
    Nov 19 at 12:52
















Does it work if you change signature to doRecoveryAction(Throwable ex)?
– Ermintar
Nov 19 at 9:40




Does it work if you change signature to doRecoveryAction(Throwable ex)?
– Ermintar
Nov 19 at 9:40












No it doesn't. Tried that as well.
– kashish verma
Nov 19 at 9:43




No it doesn't. Tried that as well.
– kashish verma
Nov 19 at 9:43












Pls, post the real pointcut & executed method signature. @ExceptionHandler doesn't spoil AOP handlers
– Ermintar
Nov 19 at 9:46




Pls, post the real pointcut & executed method signature. @ExceptionHandler doesn't spoil AOP handlers
– Ermintar
Nov 19 at 9:46












Trouble is with your pointcut expression. Try pointcut = "execution(* com.name.papp.star.*)" to scan full package or "execution(* com.name.papp.star.auth.service.impl.signInCustomer(..))" for exact method
– Ermintar
Nov 19 at 10:20




Trouble is with your pointcut expression. Try pointcut = "execution(* com.name.papp.star.*)" to scan full package or "execution(* com.name.papp.star.auth.service.impl.signInCustomer(..))" for exact method
– Ermintar
Nov 19 at 10:20












Around("execution(* com..*ServiceImpl.*(..))") works perfectly with Around , but gives error when I use AfterThrowing. Could you please suggest an alternate, I have to give package based restrictions.
– kashish verma
Nov 19 at 12:52




Around("execution(* com..*ServiceImpl.*(..))") works perfectly with Around , but gives error when I use AfterThrowing. Could you please suggest an alternate, I have to give package based restrictions.
– kashish verma
Nov 19 at 12:52

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371744%2fusing-afterthrowing-with-exceptionhandler%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371744%2fusing-afterthrowing-with-exceptionhandler%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

What visual should I use to simply compare current year value vs last year in Power BI desktop

How to ignore python UserWarning in pytest?

Alexandru Averescu