Wrapping unknown exceptions into custom exception using throws advice

Go To StackoverFlow.com

0

Is it possible to wrap an exception into a custom exception in a throwsAdvice and throw back this custom exception? E.g I have a class A with a method called as func(). This func() throws different exceptions. I apply throws advice on this func where I wrap all these exceptions into MyOwnException class and throw back MyOwnException instead.

Is this possible, please advise.

2012-04-04 20:06
by user1269597
I know this one is old, but still listed as unanswered. Would you please accept and upvote my answer if it seems appropriate? Thanks - kriegaex 2014-06-09 12:11


0

I do not know much about Spring, but with AspectJ (also usable from within Spring apps) you can use an after() throwing pointcut to catch an exception and wrap it into a RuntimeException.

Or, even better, you use the language feature called exception softening, see http://www.eclipse.org/aspectj/doc/next/progguide/semantics-declare.html#softened-exceptions and http://www.eclipse.org/aspectj/doc/next/adk15notebook/declare-soft.html.

2012-11-04 11:33
by kriegaex
Ads