-
Apr 2nd, 2012, 02:42 PM
#1
Exception Handling using AOP/AspectJ
I am trying implement Exception Handling using AOP.
Here is my Problem:
My Application is 3 level architecture i.e., container->Service->DAO. I implemented Exception Handling using AOP but it is not working if exception raised in container but if it raised in service/DAO it is working.
I have try catch in Container but not throwing here because this is last point where i have to display corresponding error message.
I am throwing Exceptions in Service/DAO but there i am not catching any exception just throwing because AOP will do that.
Here is my Problem:
When exception raised in container then AOP is catching exception and inserting in to error log but it is not returning to container and application is blowing instead of displaying proper message.
Here is my Code :
AOP implemented class:
@AfterThrowing(pointcut="execution(* com.converge.cvt..*.*(..))",throwing="exception", argNames="joinPoint, exception" )
public void exceptionHandling(JoinPoint joinPoint, Exception exception) throws APPErrorException,DBErrorException
{
System.out.println("here do somthing :" + exception.getMessage());
System.out.println("\n\n In here is : ############### : ");
String str = joinPoint.getClass().getName();
String str1 = joinPoint.getSignature().getName();
String str2 = joinPoint.getTarget().getClass().getName();
CnvgUser user = null;
if(SecurityContextHolder.getContext().getAuthentic ation()!=null)
{
System.out.println("\n\n In here SecurityContextHolder.getContext() is NULL...............");
user = (CnvgUser) SecurityContextHolder.getContext().getAuthenticati on().getPrincipal();
}
if(exception.getCause() != null){
if(!exception.getCause().getClass().getName().equa lsIgnoreCase("java.sql.SQLException")){
ErrorLog.logError(str2+" : "+str1, exception.getMessage(), exception, "", user);
throw new APPErrorException(exception.getMessage());
}else{
System.out.println("Here throwing DBErrorException");
throw new DBErrorException(exception.getMessage(), exception);
}
}else{
System.out.println("\n\n***************** In here exception.getClass().getName() is : "+exception.getClass().getName());
if(!exception.getClass().getName().equalsIgnoreCas e("java.sql.SQLException")){
System.out.println("str2 : str1 is : "+str2+" : "+str1);
ErrorLog.logError(str2+" : "+str1, " exception.getClass().getName()", exception, "", user);
exception.printStackTrace();
throw new APPErrorException("Throwing APPErrorException....111111",exception);
}else{
System.out.println("Here throwing DBErrorException");
exception.printStackTrace();
throw new DBErrorException(exception.getMessage(), exception);
}
//throw new APPErrorException(exception.getMessage(), exception);
}
}
Container try/catch code
public List<CvItemsVwBean> searchInventoryDetailRecords(CvItemsVwBean viewBean, boolean moreSearch) {
try {
Exception is raised here.........
}catch (DBErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
.........Error message to display on the screen ..............
}catch (APPErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
.........Error message to display on the screen ..............
}
Please advice,
Where I am doing Wrong?
Spring Proff
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules