Prevent crash on disconnect (client)

Added exception handling code to prevent the client crashing when
disconnecting from a server