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.

DeclareSoftRuntimeException.aj 1013B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. public aspect DeclareSoftRuntimeException {
  2. declare soft : MyRuntimeException : execution(* *(..));
  3. declare soft : MyException : execution(* *(..));
  4. declare soft : Exception : execution(void throwMyExceptionButNotReally());
  5. public static void main(String[] args) {
  6. try {
  7. throwMyRuntimeException();
  8. } catch(Exception ex) {
  9. System.out.println(ex.getClass().getName());
  10. }
  11. try {
  12. throwMyException();
  13. } catch(Exception ex) {
  14. System.out.println(ex.getClass().getName());
  15. }
  16. try {
  17. throwMyExceptionButNotReally();
  18. } catch(Exception ex) {
  19. System.out.println(ex.getClass().getName());
  20. }
  21. }
  22. private static void throwMyRuntimeException() {
  23. throw new MyRuntimeException();
  24. }
  25. private static void throwMyException() throws MyException {
  26. throw new MyException();
  27. }
  28. private static void throwMyExceptionButNotReally() throws MyException {
  29. throw new MyRuntimeException();
  30. }
  31. }
  32. class MyRuntimeException extends RuntimeException {}
  33. class MyException extends Exception {}