code_junkie

Declare-and-throw vs. throw-without-being-declared exceptions

Nov 12th, 2011
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. public void methodA() throws AnException {
  2. //do something
  3. throw new AnException();
  4. }
  5.  
  6. public void methodA() {
  7. //do the same thing
  8. throw new AnException();
  9. }
  10.  
  11. public abstract class AbstractBox {
  12. public abstract void addItem(Item newItem);
  13. public abstract void removeItem(Item oldItem);
  14. }
  15.  
  16. public class MyBox extends AbstractBox {
  17. public void addItem(Item newItem) throws ItemAlreadyPresentException {...}
  18. public void removeItem(Item oldItem) throws NoSuchItemException {...}
  19. }
  20.  
  21. public void boxHandler(AbstractBox box) {
  22. Item item = new Item();
  23. box.removeItem(item);
  24. }
Add Comment
Please, Sign In to add comment