Hi Thomas, your aspect will possibly work - I have not tried it. But the question about the used $-sign in your inner class from Oliver Boehm is legitimate. Why do you declare your inner class methods with this prefix? I think the inner class will also work without usign the $-sign in your inner class methods. Is this really a working progress for inner classes and where do I find more information about this?! In the Java specification (http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html) I didn't find any special prefix character, especially the $-character.
I know that this is not a question about AOP programming but I'm interested in your reply. Cheers, Marcus ------------------------------------------------------------------------ Marcus Walla Deutsches Elektronen-Synchrotron MCS1 phone: +49-40-8998-2628 Notkestr. 85 fax: +49-40-8994-4303 22607 Hamburg e-mail: marcus dot walla at desy dot de Germany ------------------------------------------------------------------------ >-----Original Message----- >From: [email protected] >[mailto:[email protected]] On Behalf Of Oliver Böhm >Sent: Thursday, 05 March, 2009 23:03 >To: [email protected] >Subject: Re: [aspectj-users] Exception dilemma > > >Hi Thomas, > >yes, that's exactly what I want - I tried your code and it >works. I had >a little problem to understand the code but I think the trick >here is to >use the constructor of the inner class to throw the desired exception. > >What I don't understand is the $ sign before the method name ($throw) >but I guess this is syntax for inner classes. > >thanx for your tip >Oliver > > > >Thomas Richard Darimont schrieb: >> Hi Oliver, >> >> so you want to throw an exception after some specific Methods return >> >> How about this: >> (Just a quick hack...) >> >> Aspect: >> [code] >> package de.tutorials.training.aspects; >> >> import java.io.IOException; >> >> public aspect ExampleAspect { >> pointcut applicationCode(): execution(* *..*(..)) && ! >> within(ExampleAspect); >> // after() throwing(Throwable t) : applicationCode(){ >> // } >> after() returning: applicationCode(){ >> Thrower.$throw(new IOException("oh oh")); >> } >> static class Thrower{ >> private static Throwable throwable; >> private Thrower() throws Throwable{ >> throw throwable; >> } >> public static void $throw(Throwable t){ >> throwable = t; >> try { >> Thrower.class.newInstance(); >> } catch (InstantiationException e) { >> e.printStackTrace(); >> } catch (IllegalAccessException e) { >> e.printStackTrace(); >> } >> } >> public static void $throw0(Throwable t){ >> //Questionable but okay for "debugging" purposes >> Thread.currentThread().stop(t); >> } >> } >> } >> [/code] >> >> Example: >> [code] >> package de.tutorials.training; >> >> public class Main { >> public static void main(String[] args) throws Throwable { >> try { >> m0(); >> } catch (Throwable t) { >> t.printStackTrace(); >> } >> try { >> m1(); >> } catch (Throwable t) { >> t.printStackTrace(); >> } >> >> try { >> m2(); >> } catch (Throwable t) { >> t.printStackTrace(); >> } >> } >> >> public static void m0() {} >> public static int m1() { return 0; } >> public static void m2() throws Throwable {} >> } >> [/code] >> >> Output: >> [code] >> java.io.IOException: oh oh >> at >> >de.tutorials.training.aspects.ExampleAspect.ajc$afterReturning$ de_tutorials_training_aspects_ExampleAspect$1>$d15ea11e(ExampleAspect.aj:12) >> >> at de.tutorials.training.Main.m0(Main.java:29) >> at de.tutorials.training.Main.main(Main.java:10) >> java.io.IOException: oh oh >> at >> >de.tutorials.training.aspects.ExampleAspect.ajc$afterReturning$ de_tutorials_training_aspects_ExampleAspect$1>$d15ea11e(ExampleAspect.aj:12) >> >> at de.tutorials.training.Main.m1(Main.java:32) >> at de.tutorials.training.Main.main(Main.java:15) >> java.io.IOException: oh oh >> at >> >de.tutorials.training.aspects.ExampleAspect.ajc$afterReturning$ de_tutorials_training_aspects_ExampleAspect$1>$d15ea11e(ExampleAspect.aj:12) >> >> at de.tutorials.training.Main.m2(Main.java:37) >> at de.tutorials.training.Main.main(Main.java:20) >> Exception in thread "main" java.io.IOException: oh oh >> at >> >de.tutorials.training.aspects.ExampleAspect.ajc$afterReturning$ de_tutorials_training_aspects_ExampleAspect$1>$d15ea11e(ExampleAspect.aj:12) >> >> at de.tutorials.training.Main.main(Main.java:25) >> >> [/code] >> >> Best regards, >> Thomas >> >> Oliver Böhm schrieb: >>> Hallo, >>> >>> for testing purpose I want to throw an Exception after a method >>> returns: >>> >>> after() returning throws InterruptedException : >applicationCode() { >>> throw new InterruptedException(); >>> } >>> >>> This works as expected for methods which throws >InterruptedException. >>> Now I want to make it more general and addresses *all* >methods which >>> can throw an checked exception: >>> >>> after() returning throws Exception : applicationCode() { >>> ... >>> } >>> >>> But here I got an error message ("can't throw checked exception >>> 'java.lang.Exception' at this join point...") which is >clear because >>> the pointcut "applicationCode()" addresses e.g. an >InterruptException. >>> >>> Has anybody a hint or tip how I can realize it without defining an >>> advice for each possible checked Exception? >>> >>> regards >>> Oliver >>> _______________________________________________ >>> aspectj-users mailing list >>> [email protected] >>> https://dev.eclipse.org/mailman/listinfo/aspectj-users >> >> _______________________________________________ >> aspectj-users mailing list >> [email protected] >> https://dev.eclipse.org/mailman/listinfo/aspectj-users > >-- >Oliver Böhm >http://www.javatux.de _______________________________________________ >aspectj-users mailing list >[email protected] >https://dev.eclipse.org/mailman/listinfo/aspectj-users > _______________________________________________ aspectj-users mailing list [email protected] https://dev.eclipse.org/mailman/listinfo/aspectj-users
