Simplify the exception handling code in the logout method