Improved exception handling in tcp server/client.