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.

GetCauseOnSoftException.java 629B

1234567891011121314151617181920212223242526272829303132
  1. import org.aspectj.lang.*;
  2. public class GetCauseOnSoftException {
  3. public static void a(){
  4. b();
  5. }
  6. /**
  7. * Method b.
  8. */
  9. private static void b() {
  10. throw new MyException("secret");
  11. }
  12. public static void main(String[] args) {
  13. try {
  14. a();
  15. } catch (SoftException e) {
  16. System.out.println(e.getCause());
  17. if (e.getCause().getMessage().indexOf("secret")==-1)
  18. throw new RuntimeException("Didn't get expected cause of SoftException");
  19. }
  20. }
  21. }
  22. aspect Softner {
  23. declare soft : MyException : within(GetCauseOnSoftException);
  24. }
  25. class MyException extends Exception {
  26. MyException(String s) { super(s);}
  27. }