Pardon my ignorance on the subject of C#, I'm just beginning. :)
I'm writing an application that has a need to test connectivity to a host provided by the user before performing other actions. I've attached the code that I use and it works if I provide a valid host name, but if I give an invalid host name, it crashes with the error that the host is not resolvable. I understand DNS won't resolve the host, but how can I catch that error and have the program react to it rather than crashing?
string Computer = computerName_input.Text;
Ping ping = new Ping();
PingReply reply = ping.Send(Computer);
if (reply.Status == IPStatus.Success)
MessageBox.Show("Results for " + Computer + ": " + reply.Status.ToString());
MessageBox.Show("Machine is offline");