Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] convert unchecked-exception to checked-exception

Hi,

In your particular situation you could:

 declare soft : PersistException : mypointcut();

then the DSException wouldn't get softened.

I did just prototype a compiler change that would mean the woven code
looked like this:

try {
   try {
       throw new PersistException();
   } catch(Exception exception) {
      ThrowDSExceptionAspect.aspectOf().ajc$afterThrowing$com_gid_bip_dataservice_aj_ThrowDSExceptionAspect$1$e66f2abe(exception);
      throw exception;
   }
} catch(Exception exception1) {
    if(exception1 instanceof RuntimeException)
       throw exception1;
    else {
    if (exception1 instanceof DSException) { // NEW CHECK, don't wrap
if OK to throw
      throw exception1;
    } else {
       throw new SoftException(exception1);
    }
    }
}

which also appears to get you what you want.  The DSException is not
wrapped because it is declared to be thrown at the joinpoint.  This
feels like a variation of declare soft though (so maybe a syntax
variation to request this behaviour) - and I'm not sure how often
users hit this scenario. Is the ability to control what is softened
through the declare soft type pattern sufficient for you?

cheers,
Andy


On 24 May 2012 02:06, Straub Oliver <oliver.straub@xxxxxxxxxxxxxx> wrote:
> Hello,
> there has been long discussions on checked vs. unchecked exceptions.
> I don't want to start this discussion again.
>
> I know, the opposite behaviour can be achieved by "declare soft ..."
>
> In my case i have to convert any exception to a layer-specific checked
> exception.
> This behaviour shall be controllable (on/off) with the presence of a
> method-annotation.
> Here an example:
>
>   @DSExceptionTranslator
>   private void anyMethod() throws DSException {
>       throw new PersistException();
>   }
>
> Obvious the above code will normally generate an unhandled-exception-error.
> I expected the following advice to solve that.
>
>   after() throwing (Exception ex) throws DSException : mypointcut() {
>       throw new DSException(ex);
>   }
>
> But the unhandled-exception-error did not disappear!
>
> So i added a "declare soft":
>
>   declare soft : Exception : mypointcut();
>
> The unhandled-exception-error disappears, but this did not solve my problem
> because the generated code looks like this:
>
> try {
>    try {
>        throw new PersistException();
>    } catch(Exception exception) {
>
> ThrowDSExceptionAspect.aspectOf().ajc$afterThrowing$com_gid_bip_dataservice_aj_ThrowDSExceptionAspect$1$e66f2abe(exception);
>       throw exception;
>    }
> } catch(Exception exception1) {
>     if(exception1 instanceof RuntimeException)
>        throw exception1;
>     else
>        throw new SoftException(exception1);
> }
>
> As we can see, my new DSException is softened too and is thrown as a
> SoftException.
> It seems that the code for "declare soft" will always be weaved as last
> step.
> I tried "declare precedence" to control the weaving-process, but nothing
> changes!
>
> ==== Is there any other way to avoid the unhandled-exception-error? ====
>
> I found similar Questions in several lists, but the solutions all did not
> work with the current release of AspectJ 1.6.12.M1 (ajdt 2.1.3).
>
> Thank you in advance
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top