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.

MultiCatchWithHandler.java 624B

12345678910111213141516171819202122232425262728293031323334353637
  1. public class MultiCatchWithHandler {
  2. public static void main(String[] args) {
  3. try {
  4. foo("abc");
  5. } catch (ExceptionA | ExceptionB ex) {
  6. bar(ex);
  7. }
  8. }
  9. public static void bar(Exception ea) {
  10. }
  11. public static void foo(String s) throws ExceptionA, ExceptionB {
  12. if (s.equals("ta")) {
  13. throw new ExceptionA();
  14. } else {
  15. throw new ExceptionB();
  16. }
  17. }
  18. }
  19. @SuppressWarnings("serial")
  20. class ExceptionA extends Exception {
  21. }
  22. @SuppressWarnings("serial")
  23. class ExceptionB extends Exception {
  24. }
  25. aspect X {
  26. before(ExceptionA ea): handler(ExceptionA) && args(ea) {
  27. System.out.println("in advice");
  28. }
  29. }