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.

ErrorHandling.aj 961B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import org.aspectj.lang.JoinPoint.StaticPart;
  2. import java.lang.annotation.Retention;
  3. import java.lang.annotation.RetentionPolicy;
  4. //@Retention(RetentionPolicy.RUNTIME)
  5. @interface NormalException {
  6. /** The default of Void means ANY throwable */
  7. Class[] value() default Void.class;
  8. }
  9. public aspect ErrorHandling {
  10. before(Throwable throwable) : handler(*) && args(throwable) && !@withincode(NormalException) {
  11. System.err.println("Caught in "+thisEnclosingJoinPointStaticPart.getSignature().getName());
  12. }
  13. public static void main(String argz[]) {
  14. new Test().checkConnection();
  15. }
  16. }
  17. class Test {
  18. @NormalException(Exception.class)
  19. protected void checkConnection() {
  20. try {
  21. foo();
  22. } catch (Exception e) {
  23. ;//skip warning
  24. }
  25. }
  26. private void foo() {
  27. try {
  28. throw new RuntimeException();
  29. } catch (RuntimeException e) {
  30. throw e;
  31. }
  32. }
  33. }