Hi Spring Gurus,
I have a short design/architecture question.
I plan to map all possible exceptions to one common unchecked exception. In my framework that exceptions get handled afterwards by one central exception handling class.
The code looks like the following.
My design question is now, how do you handle the retVal = pjp.proceed(); call?Code:@Pointcut (mapping to any packages...) ... exceptionMappingMethod() { } @Around("exceptionMappingMethod()") protected Object doBasicExceptionhandling(ProceedingJoinPoint pjp) throws Throwable { //Start centralized exception handling Object retVal = null; try { retVal = pjp.proceed(); } catch (UncheckedError ex) { switch(ex.getExceptionType()) { case UncheckedError.TYPE_OBJECT_LOCKED_EXCEPTION: //handle specific unchecked exception break; case UncheckedError.TYPE_OBJECT_NOTFOUND_EXCEPTION: //handle specific unchecked exception break; case UncheckedError.TYPE_ANY_EXCEPTION: //handle specific unchecked exception, but the method call need a return value Booelan(true/false) break; [...] default: throw new Exception(ex); } } return retVal; }
Let's assume that it is possible to return an new business object when a DAO exception happen. In the case that the catch block is executed no return value object is available.
What do you think about to put a possible return value into the UncheckedError, and return that value.
The unchecked exception is created like this:
new UncheckedError(UncheckedError.TYPE_ANY_EXCEPTION, <error case object>, SourceException)
The new code segment would look like the following:
thxCode:@Pointcut (mapping to any packages I need...) ... exceptionMappingMethod() { } @Around("exceptionMappingMethod()") protected Object doBasicExceptionhandling(ProceedingJoinPoint pjp) throws Throwable { //Start centralized exception handling Object retVal = null; try { retVal = pjp.proceed(); } catch (UncheckedError ex) { switch(ex.getExceptionType()) { case UncheckedError.TYPE_OBJECT_LOCKED_EXCEPTION: //handle specific unchecked exception retVal = ex.getErrorCaseObject(); break; case UncheckedError.TYPE_OBJECT_NOTFOUND_EXCEPTION: //handle specific unchecked exception retVal = ex.getErrorCaseObject(); break; case UncheckedError.TYPE_ANY_EXCEPTION: //handle specific unchecked exception retVal = ex.getErrorCaseObject(); break; [...] default: throw new Exception(ex); } } return retVal; }


Reply With Quote