Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] How to wrap an unchecked exception in a business unchecked exception?

Greetings!

A business application may have methods like this:

   public void doSomething() throws BusinessException
   {
      try
       {
         doLogic();
       }
       catch (Exception e)
       {
           throw new BusinessException(e.getMessage());
       }
   }

That is, any checked exception thrown is wrapped with an unchecked business exception. So I'd like to aspectize this concern. I've tried this advice (I've read articles that suggest this way):

   Object around() throws BusinessException : operations()
   {
       try
       {
           return proceed();
       }
       catch (Exception e)
       {
           throw new BusinessException(e.getMessage());
       }
   }

And modified the above business method:

   public void doSomething() throws BusinessException
   {
      doLogic();
   }

However, this does not work since the compiler complains about unhandled checked exceptions.

I've also tried

   declare soft: Exception : operations();

but this wraps checked exceptions in unchecked (run-time) exceptions.

Thanks,
Dmitri



Back to the top