CyberMaster0
Junior Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору Здравствуйте, есть вопрос по этому коду: Код: class Programm { public static void Main() { Ping pingSender = new Ping (); PingReply reply = pingSender.Send("www.contoso.com"); if (reply.Status == IPStatus.Success) { Console.WriteLine("Address: {0}", reply.Address.ToString()); Console.WriteLine("RoundTrip time: {0}", reply.RoundtripTime); Console.WriteLine("Time to live: {0}", reply.Options.Ttl); Console.WriteLine("Don't fragment: {0}", reply.Options.DontFragment); Console.WriteLine("Buffer size: {0}", reply.Buffer.Length); } else { Console.WriteLine(reply.Status); } } } | Если в pingSender.Send запихнуть неправильный URL, то вылетает исключение. Так вот как словить и обработать это исключение? Собственно я делал так: Код: public static void Main() { Ping pingSender = new Ping (); try { PingReply reply = pingSender.Send("www.contoso.com"); if (reply.Status == IPStatus.Success) { Console.WriteLine("Address: {0}", reply.Address.ToString()); Console.WriteLine("RoundTrip time: {0}", reply.RoundtripTime); Console.WriteLine("Time to live: {0}", reply.Options.Ttl); Console.WriteLine("Don't fragment: {0}", reply.Options.DontFragment); Console.WriteLine("Buffer size: {0}", reply.Buffer.Length); } else { Console.WriteLine(reply.Status); } } catch (Exception) { Console.WriteLine("Ошибка"); } } | Но может есть более разумный способ? |