Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

HandlerSig.java 933B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import org.aspectj.testing.Tester;
  2. import org.aspectj.lang.reflect.*;
  3. public class HandlerSig {
  4. public void doSomething() {
  5. // Get around "unreachable code error...
  6. if (true)
  7. {
  8. throw new BusinessException("Surprise!!");
  9. }
  10. System.out.println("Busy doing something.");
  11. }
  12. public static void main(String[] args) {
  13. try {
  14. HandlerSig m = new HandlerSig();
  15. m.doSomething();
  16. } catch (BusinessException be) {
  17. Tester.checkEqual(be.getMessage(), "Surprise!!");
  18. }
  19. }
  20. }
  21. class BusinessException extends RuntimeException {
  22. BusinessException(String message) {
  23. super(message);
  24. }
  25. }
  26. aspect AppMonitor {
  27. pointcut problemHandling() : handler(Throwable+);
  28. before() : problemHandling() {
  29. CatchClauseSignature cSig =
  30. (CatchClauseSignature) thisJoinPointStaticPart.getSignature();
  31. Tester.checkEqual(cSig.getParameterType(), BusinessException.class);
  32. Tester.checkEqual(cSig.getParameterName(), "be");
  33. }
  34. }