My guess is that your wc is the Webclient..
This is c#,
try
{
stream = New IO.StreamReader(wc.OpenRead(URL)
}
catch( Exception )
{
MessageBox.Show("You lost your connection");
}
Obviously you don't need to use the messagebox, but can do whatever you wish to do.