Added exception handling for hostname and IP