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.

AfterThrowingNotWoven.java 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import org.aspectj.testing.*;
  2. public class AfterThrowingNotWoven {
  3. public static void main(String[] args) {
  4. try {
  5. new Server().doSomething();
  6. } catch (FaultException fe) {
  7. Tester.event("caught-in-main");
  8. }
  9. Tester.checkAllEvents();
  10. }
  11. static {
  12. Tester.expectEvent("caught");
  13. Tester.expectEvent("caught-in-main");
  14. }
  15. }
  16. class Server {
  17. public void doSomething() {
  18. System.out.println("Doing something.");
  19. throw new FaultException();
  20. }
  21. }
  22. class DisabledException extends RuntimeException {}
  23. class FaultException extends RuntimeException {}
  24. aspect FaultHandler {
  25. private boolean Server.disabled = false;
  26. private void reportFault() {
  27. System.out.println("Failure! Please fix it.");
  28. }
  29. public static void fixServer(Server s) {
  30. s.disabled = false;
  31. }
  32. pointcut service(Server s): target(s) && call(public * *(..));
  33. before(Server s): service(s) {
  34. if (s.disabled) throw new DisabledException();
  35. }
  36. after(Server s) throwing (FaultException e): service(s) {
  37. s.disabled = true;
  38. Tester.event("caught");
  39. }
  40. }