Seems to work for me:
mucuna ~/workspaces/abc/MyABCTest/src $ java -cp
.:../../abc/lib/abc-runtime.jar Example
Before advice ...
Inside finally ...
Exception in thread "main" java.lang.ArithmeticException: / by zero
at Example.shadow$6(Example.java:12)
at TestAspect.inline$0$around$0(TestAspect.java:9)
at Example.a(Example.java)
at Example.main(Example.java:20)
Note though that you have to use a qualified type to make your code compile:
declare soft: java.io.IOException: call(* Example.*(..));
and not:
declare soft: IOException: call(* Example.*(..));
Also note that you don't "see" the finally block in the Jimple output,
as it is implemented via traps. Those traps jump to the appropriate
Jimple statements when the exception is raised.
Eric
2009/3/11 <hsadat_at_gmail.com>:
> Hi,
> I have an issue with exceptions again but not directly related (I think) to
> my previous email.
> I noticed that, when using abc.ja 1.3.0 to compile the following code, the
> finally block is not executed when an exception is raised. I checked the
> generated Jimple code (below), and it looks like the code inside the finally
> has simply been copied right after the code of try. Therefore, when an
> exception is raised, the finally code gets no chance to run. Here is the
> code:
> public class Example{
>
> public void a(String str) throws IOException
> {
> PrintWriter pr = null;
>
> pr = new PrintWriter("out.txt");
> int i = 1;
> if(i > 0)
> i = i / (1-i);
>
> pr.println(str);
> pr.close();
>
> }
> public static void main(String[] args)
> {
> new Example().a("test");
> }
> }
> aspect TestAspect{
>
> declare soft: IOException: call(* Example.*(..));
>
> pointcut newprint(): execution(* Example.a(..));
>
> void around(): newprint()
> {
> System.out.println("Before advice ...");
> try{
>
> proceed();
> }
> finally
> {
> System.out.println("Inside finally ...");
> }
>
> }
> }
> and here's the generated advice code (please note that it's un-optimized
> code:)
> public void around$0(Abc$proceed$TestAspect$around$0, int, int, int,
> java.lang.Object)
> {
> TestAspect this;
> java.io.PrintStream temp$0, temp$1;
> java.lang.String uniqueArgLocal2, uniqueArgLocal3;
> Abc$proceed$TestAspect$around$0 closureInterface1;
> int shadowID2, staticClassID3, bindMask4;
> java.lang.Object contextArgFormal$11;
> this := @this: TestAspect;
> closureInterface1 := @parameter0: Abc$proceed$TestAspect$around$0;
> shadowID2 := @parameter1: int;
> staticClassID3 := @parameter2: int;
> bindMask4 := @parameter3: int;
> contextArgFormal$11 := @parameter4: java.lang.Object;
> temp$0 = <java.lang.System: java.io.PrintStream out>;
> uniqueArgLocal2 = "Before advice ...";
> virtualinvoke temp$0.<java.io.PrintStream: void
> println(java.lang.String)>(uniqueArgLocal2);
> staticinvoke <Example: void
> abc$static$proceed$TestAspect$around$0(int,int,java.lang.Object)>(shadowID2,
> bindMask4, contextArgFormal$11);
> temp$1 = <java.lang.System: java.io.PrintStream out>;
> uniqueArgLocal3 = "Inside finally ...";
> virtualinvoke temp$1.<java.io.PrintStream: void
> println(java.lang.String)>(uniqueArgLocal3);
> goto label0;
> label0:
> return;
> }
> Thanks in advance.
> --Hossein
-- Eric Bodden Sable Research Group, McGill University Montréal, Québec, CanadaReceived on Sat Mar 14 2009 - 17:50:27 GMT
This archive was generated by hypermail 2.2.0 : Sat Mar 14 2009 - 20:10:11 GMT