25 Example Exception Handling Catch any exception in all the public methods: aspect CatchException{ // Catch any exception in all the public methods void around(): execution(public * *(..)){ try{ proceed(); } catch(Exception e){ System.out.println( Printing exception ); //Handle exception } Catch SQL exceptions that need to be logged: after() throwing (SQLException ex) : inDataLayer() { logException(ex); } Throwing of exception: aspect ThrowException { private boolean Point.inGroup = false; before(Point p): execution(void Group.add(FigureElement)) && args(p) { if (p.inGroup) { throw new IllegalStateException(); } else { p.inGroup = true; }
{}