More safely extract the host name, in the case of an exception.