I am trying to catch any errors that crop up when a URL is invalid, below is the original code:
public static void mymethod()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(firstline);
Stopwatch timer = new Stopwatch();
timer.Start();
using (var response = request.GetResponse())
timer.Stop();
timeTaken = timer.Elapsed.ToString();
}
I have tried to create an exception handler as below, but no luck:
public static void mymethod()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(firstline);
Stopwatch timer = new Stopwatch();
timer.Start();
try
{
using (var response = request.GetResponse())
}
catch
{
Console.WriteLine("error here...")
}
timer.Stop();
timeTaken = timer.Elapsed.ToString();
}