Re: [abc-users] SoftException

From: <hsadat_at_gmail.com>
Date: Wed, 11 Mar 2009 11:02:45 -0600

Thanks Eric. That makes sense. For some reason I thought the
"declare"s will always take effect first, and now find it annoying
that I can't enforce the desired precedence (that the softening happen
before other advice.)

To be honest, this seems like a feature to me, because I use declare
soft just to stop Java nagging about unhandled checked exceptions to
be able to handle them in the aspect. Now, it seems that there are
ways to accomplish the above without having to deal with SoftExceptions.

--Hossein

On 11-Mar-09, at 10:11 AM, Eric Bodden wrote:

> I think this may be a precedence issue between your "declare soft"
> declaration and the around advice. Two things happen at your execution
> joinpoint: (1) the softening of the exception and (2) the application
> of the around advice. If (2) happens before (or within) (1) then this
> would explain what you see.
>
> Eric
>
> 2009/3/11 <hsadat_at_gmail.com>:
>> Here is a simple class and an aspect (I copy paste the whole code
>> just not
>> to miss anything relevant; I also attach the files:)
>> import java.io.*;
>> import java.util.*;
>> import org.aspectj.lang.*;
>>
>> public class BufReaderException {
>> public void g()
>> {
>> BufferedReader in = new BufferedReader(new
>> FileReader("nonExistingFile"));
>> String str = null;
>> while ( (str = in.readLine()) != null )
>> {
>> System.out.println(str);
>> int i = 1;
>> int j = i / (i*1 - 1);
>> }
>> in.close();
>> }
>> public static void main(String[] args)
>> {
>> BufReaderException example = new BufReaderException();
>> example.g();
>> }
>> }
>>
>> import java.io.*;
>> import java.util.*;
>> import org.aspectj.lang.*;
>>
>> aspect ExceptionTest perthis(gExec()){
>>
>> declare soft : Exception : gExec();
>>
>> pointcut gExec(): execution(* BufReaderException.g());
>>
>>
>> void around(): gExec()
>> {
>> System.out.println("[Inside ExceptionTest Aspect] Around advice
>> running;
>> before proceed()");
>> try
>> {
>> proceed();
>>
>> }
>> catch(SoftException e)
>> {
>> System.out.println("[Inside ReaderExceptionAspect] Caught
>> SoftException; " +
>> e);
>> System.out.println("Wraps: " + e.getCause());
>>
>> }
>> catch(IOException e)
>> {
>> System.out.println("[Inside ExceptionTest Aspect] Caught
>> IOException; " +
>> e);
>>
>> }
>> catch(Exception e)
>> {
>> System.out.println("[Inside ExceptionTest Aspect] Caught Exception;
>> " + e);
>> }
>> finally
>> {
>>
>> System.out.println("[Inside ExceptionTest Aspect] In finally");
>> }
>>
>> System.out.println("[Inside ExceptionTest Aspect] Around advice
>> running;
>> after proceed()");
>> }
>>
>> }
>>
>> And here is the output:
>> [Inside ExceptionTest Aspect] Around advice running; before proceed()
>> [Inside ExceptionTest Aspect] Caught IOException;
>> java.io.FileNotFoundException: out1.txt (No such file or directory)
>> [Inside ExceptionTest Aspect] In finally
>> [Inside ExceptionTest Aspect] Around advice running; after proceed()
>>
>> From the output, I understand that the IOException was caught and
>> not a
>> SoftException.
>>
>> --Hossein
>>
>>
>>
>> On 11-Mar-09, at 7:59 AM, Eric Bodden wrote:
>>
>> Hi Hossein.
>>
>> I think you must be missing something. I doubt that both compilers
>> are
>> doing something wrong there. Can you email a simple test case for us
>> to look at?
>>
>> Eric
>>
>> 2009/3/10 <hsadat_at_gmail.com>:
>>
>> Hi,
>>
>> Are checked exceptions still wrapped in a SoftException, when
>> thrown at a
>>
>> softened join point?
>>
>> In a simple example, I softened the "Exception" on a pointcut and
>> caught the
>>
>> thrown checked exception (IOException in this case). As far as I
>> remember,
>>
>> SoftException is supposed to be thrown when a checked exception
>> occurs at a
>>
>> softened join point; not only I could not catch any SoftException,
>> but I
>>
>> also could directly catch IOException and others. So, have things
>> changed in
>>
>> newer AspectJ versions, or am I missing something?
>>
>> I tested this with abc 1.3.0 as well as AJDT 1.6. 3., and got the
>> same
>>
>> behaviour.
>>
>> Thanks in advance.
>>
>> --Hossein
>>
>>
>>
>>
>>
>> --
>> Eric Bodden
>> Sable Research Group, McGill University
>> Montréal, Québec, Canada
>>
>>
>>
>>
>
>
>
> --
> Eric Bodden
> Sable Research Group, McGill University
> Montréal, Québec, Canada
>
Received on Wed Mar 11 2009 - 17:02:52 GMT

This archive was generated by hypermail 2.2.0 : Wed Mar 11 2009 - 22:20:11 GMT