Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-dev] Exceptions thrown from finally block

Hi,

We’re seeing some weird behaviour when compiling some code with the 1.5.4 version of the AspectJ compiler, both from the command line and through the Eclipse plugin. I have this pretty convoluted class:

 

public class ExceptionTest

{

    public void doSomething()

    {

        throw new RuntimeException("From doSomething");

    }   

 

    public int run()

        throws Throwable

    {

        try {

            return 0;

        } catch (Throwable t) {

            System.out.println("Catch");

            throw new RuntimeException("From catch");

        } finally {

            System.out.println("Finally");

            try {

                doSomething();

            } catch (Throwable t) {

                System.out.println("Last catch");

                throw new RuntimeException("From catch finally");

            }

        }

    }

 

    public static void main(String[] arg)

        throws Throwable

    {

        new ExceptionTest().run();

    }

}

 

Note that there are no aspects being woven into this class. But after just compiling with AspectJ it gives the following output:

 

Finally

Last catch

Catch

Finally

Last catch

Exception in thread "main" java.lang.RuntimeException: From catch finally

            at com.eharmony.samplematch.ExceptionTest.run(ExceptionTest.java:24)

            at com.eharmony.samplematch.ExceptionTest.main(ExceptionTest.java:32)

 

So the Exception thrown from the finally block is caught by the earlier catch block. With the regular Java compiler, instead I get the expected:

 

Finally

Last catch

Exception in thread "main" java.lang.RuntimeException: From catch finally

            at com.eharmony.samplematch.ExceptionTest.run(ExceptionTest.java:24)

            at com.eharmony.samplematch.ExceptionTest.main(ExceptionTest.java:32)

 

The problem seems to be related to the “return 0” inside the first try block. If I move that statement out to the last line of the run() method things work fine.

 

Any ideas on this? I’d be happy to file a bug if that’s the case.

Thanks,

/ Per

 

 


Back to the top