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.

PR78021.java 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. public class PR78021 {
  2. protected static Integer counter = new Integer(4);
  3. public static void main(String[] args) throws Exception {
  4. try {
  5. doSomething();
  6. System.err.println("TEST HAS PASSED");
  7. } catch (Exception e) {
  8. System.err.println("TEST HAS FAILED: Exception thrown by doSomething: " +e.getMessage());
  9. throw e;
  10. }
  11. }
  12. public static void doSomething() {
  13. int i = 0;
  14. while (i++<1) {
  15. counter=null;
  16. try {
  17. counter = new Integer(4);
  18. // The inclusion of the next line changes the weaving ! If it is included the woven code is wrong and the exception escapes
  19. if (counter == null) { break; }
  20. commit();
  21. } catch (Throwable e) {
  22. System.err.println("Caught exception " + e);
  23. } finally {
  24. System.err.println("In finally block");
  25. }
  26. }
  27. }
  28. protected static void commit() throws MyException {
  29. System.err.println("Main.commit");
  30. }
  31. }
  32. class MyException extends Exception { MyException(String s,String s2) { super(s); } }
  33. aspect SimpleExceptionThrowingAspect {
  34. pointcut commitOperation() : call (* PR78021+.commit(..));
  35. before() throws MyException : commitOperation() {
  36. throw new MyException("Dummy My Exception", "55102");
  37. }
  38. }