Use correct exception and improve host check