exception handling and session cleanup