1 / 31

Exception Handling Framework in AOP

Kimaya Kamat. Exception Handling Framework in AOP . Outline. Background Exception Handling Exception Handling with AOP Bugs in AOP Exception Handling. Exceptions. A disruption in the normal flow of the program An unwanted condition Unchecked exceptions Checked exceptions.

yonah
Download Presentation

Exception Handling Framework in AOP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Kimaya Kamat Exception Handling Framework in AOP

  2. Outline • Background • Exception Handling • Exception Handling with AOP • Bugs in AOP Exception Handling

  3. Exceptions.. • A disruption in the normal flow of the program • An unwanted condition • Unchecked exceptions • Checked exceptions

  4. Java code snippet with assertions.. public class Stack { public Object [] array; private inttopOfStack = 0; public void push(Object obj) { assert (0 <= topOfStack)&& (topOfStack < array.length); this.array[topOfStack++] = obj; assert (0 <= topOfStack)&& (topOfStack < array.length); } public Object pop() { assert (0 <= topOfStack)&& (topOfStack < array.length); Object result = this.array[topOfStack-1]; this.array[topOfStack-1] = null; this.topOfStack- - ; assert (0 <= topOfStack)&& (topOfStack < array.length); return result; } public () Object peek(){ assert (0 <= topOfStack)&& (topOfStack < array.length); Object result = this.array[topOfStack-1]; assert (0 <= topOfStack)&& (topOfStack < array.length); return result; } ... }

  5. The Contract Enforcement Pattern • Also called the Design by Contract • Add contracts to an aspect • Contract checking done at runtime • Contracts support inheritance

  6. Contracts • Set of mutual obligations between classes and their clients • Preconditions • Post-conditions • Invariants

  7. Contract 4 Java • @Requires • @Ensures • @Invariant

  8. Contract code @Invariant("size() >= 0") interface Stack<T> { public int size(); @Requires("size() >= 1") public T peek(); @Requires("size() >= 1") @Ensures({ "size() == old(size()) - 1", "result == old(peek())" }) public T pop(); @Ensures({ "size() == old(size()) + 1", "peek() == old(obj)" }) public void push(T obj); }

  9. Basic Idea of AOP • Create modularized code • Avoid tangled code • Promote reuse • Ease of maintenance .....All this applied to exception handling!

  10. AspectJ • Exception handling: • After Throwing • After Returning

  11. An Example…

  12. Exception Handling

  13. Exception Handling in AOP

  14. AOP exception handling constructs • Some are taken from Java: • Try, catch, finally • Throws • Some are it’s own! • Declare soft • After and After Throwing advice

  15. Bug Patterns in AOP • When aspects are used to catch Exceptions • When aspects throw exceptions

  16. When Aspects Catch Exception:

  17. Exception Stealing..

  18. Fragile Catch • Happens due to minor spelling mistakes

  19. Fragile Catch.. • Or even differing return types:

  20. Residual Catch.. • Before aspectiz-ing:

  21. Residual Catch…

  22. When Aspects THROW Exceptions…

  23. Throw without catch • What if log(ex) throws an exception when the file gets too large!!

  24. Path Dependent Throw • A condition where an exception should be thrown when methodC() is called through the following path: • methodA()  methodC() • Happens due to extensive use of • within, withincode, cflow, cflowbelow

  25. Conclusions

  26. Exception Handling in AOP • Advantages: • Exception handling code concentrated in the aspects • Clear separation of business code and exception handling • Reusable code • Free of duplication

  27. Exception Handling in AOP • Disadvantages • Knowledge of aspects required • No clear connection between the aspects and classes • Environment support required • Design needs to be documented precisely

  28. References: • Lippert, Martin, and Cristina Videira Lopes. A study on exception detection and handling using aspect-oriented programming. Limerick: ACM, 2000. Print. • Coelho, Roberta , Awais Rashid, James Noble, and Carlos Lucena. “A Catalogue of Bug Patterns for Exception Handling in Aspect-Oriented Programs." ACM 978 (2008): 1-13. Print. • Henrique Rebelo, Roberta Coelho, AlexandreMota.”The Contract Enforcement Aspect Pattern” • http://jcontractor.sourceforge.net/

  29. The End…

More Related