Re: [abc-users] SoftException

From: Eric Bodden <eric.bodden_at_mail.mcgill.ca>
Date: Wed, 11 Mar 2009 12:11:32 -0400

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 - 16:11:37 GMT

This archive was generated by hypermail 2.2.0 : Wed Mar 11 2009 - 17:10:12 GMT