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

On 25 May 2012 01:38, Straub Oliver <oliver.straub@xxxxxxxxxxxxxx> wrote:
> The drop of bitterness is that i have to be very carefull with this
> solution. Couldn't we have a Solution without the "declare soft"-line?
> The "after() throwing" advice will catch the Persist-Exception. The Compiler
> does not need to generate an unhandled-exception-error.

There are a couple of reasons we don't do this right now:

- we aren't setup to analyze advice and work out what it is doing, we
don't know that you are translating the exception.  Ok I could special
case when the after throwing body is purely a throw, but what would I
do in this case?

          after() throwing (Exception ex) throws DSException : mypointcut() {
		  if (something()) {
		       throw new DSException(ex);
		  } else {
		       throw new OtherUncheckedException(ex);
		  }
	  }
that would still require the declare soft probably.

- we don't let advice affect type checking right now (we could debate
whether exception handling is type checking, but it is done at the
same time as type checking right now).  Advice is treated as an
entirely different thing from declare soft or other ITDs and
matched/woven at a different time in the build process.  When the
compiler is about to produce the message about the uncaught exception,
we have no idea that after advice may sort it out later, but we do
know that there is a declare soft in effect.  This is all 'just
programming' of course and it could be made to work, but when the
simple declare soft exception option exists it is tricky to justify
doing all the re-engineering.  I will agree there is code bloat with
requiring the declare soft, but it is just an exception handler block
and not going to affect the main line.

Andy

> 2012/5/24 Andy Clement
>>
>> 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 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
>> >
>> _______________________________________________
>> aspectj-users mailing list
>> aspectj-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>