Add an error listener to prevent socket hang up and similar errors leading to thrown exceptions.