You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AfterReturningHandler.java 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import org.aspectj.testing.Tester;
  2. public class AfterReturningHandler {
  3. public static void main(String[] args) {
  4. AfterReturningHandler p = new AfterReturningHandler();
  5. p.mIntThrowing();
  6. Tester.checkAndClearEvents(new String[] {"returned null" }); // will probably say "returned null" for all below
  7. p.mVoidThrowing();
  8. Tester.checkAndClearEvents(new String[] { });
  9. p.mIntThrowingReturning();
  10. Tester.checkAndClearEvents(new String[] { });
  11. p.mVoidThrowingReturning();
  12. Tester.checkAndClearEvents(new String[] { });
  13. }
  14. public void mVoidThrowing() {
  15. try { throw new RuntimeException(); }
  16. catch (RuntimeException e) {
  17. }
  18. }
  19. public int mIntThrowing() {
  20. try { throw new RuntimeException(); }
  21. catch (RuntimeException e) {
  22. }
  23. return 3;
  24. }
  25. public void mVoidThrowingReturning() {
  26. try { throw new RuntimeException(); }
  27. catch (RuntimeException e) {
  28. return;
  29. }
  30. }
  31. public int mIntThrowingReturning() {
  32. try { if (true) throw new RuntimeException(); }
  33. catch (RuntimeException e) {
  34. return 3;
  35. }
  36. return 999999;
  37. }
  38. AfterReturningHandler() {
  39. }
  40. }
  41. aspect A {
  42. private void callEvent(String s, Object o) {
  43. Tester.event(s + " " + o);
  44. }
  45. after() returning (Object o) : handler(RuntimeException) {
  46. callEvent("returned ", o);
  47. }
  48. }