Improved socket exception handling.