Add socket exception handling